Chapter 4. Classes

Although functions allow you to define code that can be reused, it's often more useful to combine those functions into logical groupings that define the behavior of a particular type of object. This is standard object-oriented programming, which is implemented in Python by way of types and classes. These, like functions, may seem simple enough on the surface, but there's a considerable amount of power behind them that you can leverage.

The most basic idea of a class is that it encapsulates the behavior of an object, while an instance of the class represents the data for the object. Therefore, even though data may well change from one instance to another, behavior determined by the underlying class will remain the same across ...

Get Pro Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.