Python: OOP
self vs cls
- cls belongs to the class (static method)
- self refer to
instance of class
__call__
this method enables to write classes where the instances behave like functions and can be called like a function
class Example:
def __init__(self):
print("Instance Created")
# Defining __call__ method
def __call__(self):
print("Instance is called via special method")
# Instance created
e = Example()
# __call__ method will be called
e()
# Instance Created
# Instance is called via special method