This chapter rounded out our look at functions and built-in iteration tools with a larger case study that measured the performance of iteration alternatives and Pythons, and closed with a review of common function-related mistakes to help you avoid pitfalls. The iteration story has one last sequel in Part VI, where we’ll learn how to code user-defined iterable objects that generate values with classes and __iter__, in Chapter 30’s operator overloading coverage.
This concludes the functions part of this book. In the next part, we will expand on what we already know about modules—files of tools that form the topmost organizational unit in Python, and the structure in which our functions always live. After that, we will explore classes, tools that are largely packages of functions with special first arguments. As we’ll see, user-defined classes can implement objects that tap into the iteration protocol, just like the generators and iterables we met here. In fact, everything we have learned in this part of the book will apply when functions pop up later in the context of class methods.
Before moving on to modules, though, be sure to work through this chapter’s quiz and the exercises for this part of the book, to practice what we’ve learned about functions here.