Operator Overloading & Dunder Methods - Python Tutorials For Absolute Beginners in Hindi #67
Operator Overloading & Dunder Methods - Python Tutorials For Absolute Beginners in Hindi #67
Python usually calls dunder methods under the hood. Suppose we want
to join a string with a number using the + sign. Now joining between two
different data types is not possible in Python, and the resultant in such a
case will be an error. So for this purpose, we can use a function provided
to us by Python, named as dunder function. We will write such code in it
so that it may first convert the number to a string and then join them or
any other logic will be fine too until it does what we require. We can even
return 85, regardless of what string or number is given to us, it is all up to
us.
no_of_leaves = 8
self.name = aname
self.salary = asalary
self.role = arole
def printdetails(self):
@classmethod
cls.no_of_leaves = newleaves
def __repr__(self):
def __str__(self):
print(str(emp1))