A class consists of data and the functions that act on that data. In classes, functions are referred to as methods. A way to understand classes is to think of them as functions with multiple entry points. In this way they provide data encapsulation.

You define a class with the class keyword.

class class_name:

Classes can have many attributes. These attributes can be variables or definitions of either functions or other classes. For example, the definition of the class chapter has three variable attributes: number_of_pages, title, and toc.

class chapter:
        number_of_pages = 20
        title = "Organizing your program"
        toc = ["Introduction", "Modules", "Functions", "Packages", "Classes"]

Notice that the class attributes are indented, ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with O’Reilly online learning.

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