Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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__() method so that an instance...