# officially called as dunder methods
# mostly class in python is a subclass of objects which has dunder methods.
class Test:
def __str__(self):
return "This is just for test"
def __add__(self, x):
return 6 + x
sample = Test()
print(sample) # calls __str__, also gets called when str(sample)
print(sample + 9) # calls __add__
# Refer this for many such methods: https://diveintopython3.net/special-method-names.html
Double underscore methods are special methods defined by Python
that can serve a special purpose.
Ex:
__eq__ : determines what to do when determining
equality (==) of a certain object