In Python, you can almost complete all object-oriented programming elements in C + +.
Inheritance: Python supports multiple inheritance:
Class Derived (Base1, Base2, BASE3):
Pass
Polymorphic: All instance methods in Python are of type virtual
Packaging:
This is very special, C + + programming has been emphasized more is: in order to hide the implementation, all member variables are private type, and those that are only related to the implementation, not as an external interface methods are defined as private type (or protected). But in Python, there is no real private type, according to the Google Python style guide, for simple member variable access, you should directly pass the member's way without deliberately defining an access function. Also, the way to implement private is through code obfuscation. And look at the following code:
Class T (object):
def __init__ (self):
self.__x = 1.0
def __func (self):
Print ("Test")
t = t ()
T._t__func ()
Print (t._t__x)
Since the name of the member is preceded by two underscores (which require at least two), the resulting member name is confused and cannot be accessed by the original name. But still accessible, all private access controls inside Python
It is more a convention than a direct segregation of language features.
Finally, the understanding of the class in Python feels more like a namespace (which can be understood as a hash table that corresponds to a variable ID), and the name can be added dynamically (such as adding a member variable to an instance)
Object-oriented programming in Python