Professional Documents
Culture Documents
50.operator Overloading & Dunder Methods Python
50.operator Overloading & Dunder Methods Python
Check https://docs.python.org/2/library/operator.html to
explore more about operator overloading.
class Employee:
no_of_leaves = 8
def printdetails(self):
return f"The Name is {self.name}. Salary is {self.salary} and role is {self.role}"
@classmethod
def change_leaves(cls, newleaves):
cls.no_of_leaves = newleaves
def __repr__(self):
return f"Employee('{self.name}', {self.salary}, '{self.role}')"
def __str__(self):
return f"The Name is {self.name}. Salary is {self.salary} and role is {self.role}"