O'Reilly logo

XML Processing with Python by Sean McGrath

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.6. Object Orientation

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required