CHAPTER 4

image

Classes

In Chapter 3 you reviewed how functions allow you to define code that can be reused. This allowed for general code streamlining by not having to retype “chuncks” of code. However, it’s often more useful to combine those same functions into logical groupings that define the behavior and attributes of a particular type of object. This is standard object-oriented (OO) 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 ...

Get Pro Python, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.