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 nesteddefstatements; 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
classstatement generate class attributes, and classes inherit attributes from all other classes listed in theirclassstatement header line (multiple inheritance is supported; this is discussed in a moment).- Instance object creation
Calling a class object as ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access