O'Reilly logo

Programming Python, Second Edition by Mark Lutz

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

Appendix C. Python Versus C++

This appendix briefly summarizes some of the differences between Python and C++ classes. Python’s class system can be thought of as a subset of C++’s. Although the comparison to Modula 3 may be closer, C++ is the dominant OOP language today. But in Python, things are intentionally simpler -- classes are simply objects with attached attributes that may have links to other class objects. They support generation of multiple instances, customization by attribute inheritance, and operator overloading, but the object model in Python is comparatively uncluttered. Here are some specific differences between Python and C++:

Attributes

There is no real distinction between data members and methods in Python; both simply designate named attributes of instances or classes, bound to functions or other kinds of objects. Attributes are names attached to objects, and accessed by qualification: object.attribute. Methods are merely class attributes assigned to functions normally created with nested def statements; members are just attribute names assigned to other kinds of objects.

Class object generation

Class statements create class objects and assign them to a name. Statements that assign names within a class statement generate class attributes, and classes inherit attributes from all other classes listed in their class statement header line (multiple inheritance is supported; this is discussed in a moment).

Instance object creation

Calling a class object as ...

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