Tweeted By @python_tip
Adding __call__ method makes an object callable.
— Daily Python Tip (@python_tip) June 10, 2019
class add_n:
def __init__(self, n):
self.n = n
def __call__(self, x):
return x + self.n
>>> add3 = add_n(n=3)
>>> add3(9)
12
This can be really useful for decorators:https://t.co/dsfsdN6um2 pic.twitter.com/rxpezDXkFV