Journey to Master Python (WIP)

ageekymonk
2,879 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Callables

At first glance we think functions and methods are the only callables. But in python any object can be callable provided its class has implemented __call__ method. This means objects can also act as functions.

You can check if an object is callable using callable builtin function

Callables
1
2
3
4
5
6
class Log:
def __call__(self, pstr):
print(pstr)
log = Log()
log("hello world")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content