Chapter 7. Sufficiently advanced technology...

 

This chapter covers

  • More advanced features of classes
  • Generators
  • Functional programming

In this chapter, we’re going to be looking at some of the more advanced tasks Python can do. In chapter 1, you learned that Python is known as a multi-paradigm language, which means it doesn’t confine you to just one way of doing things. There are three main styles of programming: imperative, object-oriented, and functional. Python lets you work with all three, and even mix and match them where necessary.

We’ve already covered imperative and most of object-oriented programming in the chapters so far, so this chapter will focus mostly on functional programming and the more advanced parts of object-oriented programming in Python.

Object orientation

Let’s start by taking a second look at how object-oriented classes should be organized, using two separate methods: mixin classes and the super() method.

Mixin classes

Sometimes you don’t need an entire class to be able to do something. Perhaps you only need to add logging, or the ability to save the state of your class to disk. In these cases, you could add the functionality to a base class, or to each class that needs it, but that can get pretty repetitive. There’s an easier way, called a mixin class.

Customizing classes

 
 
 

Generators and iterators

 
 
 
 

Using generators

 
 

Functional programming

 
 

Where to from here?

 
 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest