Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

Chapter 11: Classes

a photograph of apples in different colors, separated into different baskets
Figure 11.1 credit: modification of work "Fresh, bright apples newly picked", by Colorado State University Extension/Flickr, Public Domain

A programmer can model real-world entities as objects for better program design and organization. A class defines a type of object with attributes and methods. Many instances of a class type can be created to represent multiple objects in a program.

Classes promote reusability. Classes add benefits like data abstraction and encapsulation, which organize code for better usability and extensibility.

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.