- Class: A class is a real or a virtual entity that has relevance to the problem at hand and has sharp physical boundaries.
- Object: An object is an instance of a class.
- Encapsulation: The clubbing together of the data and the functions that operate on the data is called encapsulation.
- Inheritance: The art of dividing the class into subclass(es) is inheritance.
- Operator overloading: Operator overloading, in general, means using the same operator in more than one way.
- Function overloading: This means having more than one function with the same name in a class with different arguments.
- A class in Python can be sub-classed.
- Multiple inheritance is also supported in Python.
- Method overriding is also allowed in Python.
- Classes can be created at runtime and can even be changed at runtime.
- In a class all data members are public in nature so they can be accessed anywhere in the program.
A class can be defined using the class
keyword. The class
keyword is followed by the name of the class. The body of the class follows:
Syntax
class <name of the class>: def <function name>(<arguments>): ... <members>
Example:
class employee:
def getdata(self):
self.name=input('Enter name\t:')
self.age=input('Enter age\t:')
def putdata(self):
print('Name\t:',self.name)
print('Age\t:',self.age)
e1=employee()
e1.getdata()
e1.putdata()
Definition: Instance variable and class variable
An instance variable is one which is unique to each instance and a class variable is one which is shared by all instances.