Looking at the five kinds of callables
Python offers five variations on the theme of a function. Each of these is a kind of callable object: we can call the object with argument values and it returns a result. Here's how we'll organize our exploration:
- Basic functions created with the
def
statement are the subject of this chapter. - Lambda forms are a function definition reduced to parameters and an expression; this is also a topic within this chapter.
- Generator functions and the yield statement are something we'll look at in Chapter 8, More Advanced Functions. These functions are iterators which can provide multiple results.
- Function wrappers for class methods are something we'll look at in Chapter 11, Class Definitions. These are built-in functions which leverage features of a class. A function like
len()
is implemented by the__len__()
method of a collection. - Callable objects are also part of Chapter 11, Class Definitions. These are classes which include the
__call__()
...