Example: Defining a
self is a special parameter which makes reference to the object itself and is always the first parameter. However, it is not supplied as an argument.
Static variables are shared among all instances of the class. For example, if we have an
num_of_employees can be a static variable which keeps count of the total number of employees.
To print an object, we can define a method 'show'.
Otherwise, we need to tell Python how to convert the object into a string by overriding the
Just as how we overrode the default
__str__ method, we can override the other default methods such as the
+ arithmetic operator.
Shallow equality compares the references of two objects. To have deep equality, where we compare the contents of the two objects, we need to override the
__eq__ method. Other relational operators such as less than can be achieved by overriding the