The seven flavors of callable objects[i.e. () operator]:
- User-defined functions: created with
defstatements or lambda expressions - Built-in functions: like
lenortime.strftime(implemented in C) - Built-in methods: methods implemented in C, like
dict.get - Methods: functions defined in the body of a class.
- Classes: when invoked, a class runs its
__new__method to create an instance, then__init__to initialize it, and finally the instance is returned to the caller. Because there is no new operator in Python, calling a class is like calling a function - Class instances: if a class defines a
__call__method, then its instances may be invoked as functions - Generator functions: functions or methods that use the
yieldkeyword. When called, generator functions return a generator object.