Back
Close

Journey to Master Python (WIP)

ageekymonk
8,300 views

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
class Log:
def __call__(self, pstr):
print(pstr)
log = Log()
log("hello world")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants