June 2002
Beginner to intermediate
640 pages
14h 24m
English
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: class_attributes
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, ...
Read now
Unlock full access