June 2000
Intermediate to advanced
556 pages
8h 45m
English
We have already encountered some of Python's object-orientation features in the discussion of the list and dictionary built-in classes.
In this section, we talk about declaring classes and creating objects. We also take a look at how inheritance works in Python.
Classes are created with the class keyword. The code below creates a trivial class foo that has a class variable x.
CD-ROM reference=5092.txt >>> class foo: ... x = 1 >>> print foo.x 1
Objects can be created from the class foo in a syntax reminiscent of a function call:
CD-ROM reference=5093.txt >>> class foo: ... x = 1 ... >>> f = foo() >>> print f.x 1
Classes can contain methods. Methods are defined in a syntax similar to that for functions. The big difference ...
Read now
Unlock full access