Callable (callable) in Python

Types that can be called as a function.

Examples of entities that can be called:

  • Built-in and custom functions ;
  • Built-in and custom methods;
  • Generator functions;
  • Classes (both classic and new style);
  • Instances of classes.

Types that support the ability to call them as a function accept a set of arguments, which, however, can be empty.

Call always is followed by the return of some value (possibly None) unless an exception is thrown. 

  # Call the generic function len () 
# passing a list as the only argument
# and returning the computed length of the list.
len ( [1, 2, 3]) # 3

The details of how the value is calculated depends on the type of object being called. 

Get Solution for free from DataCamp guru