1.Python only class One says that there is no interface to say that it supports multiple class inheritance, subclasses inherit the parent class, and can override public and protected methods, variables in the parent class.
2.Python variables, functions are public by default, single underline variables, function representatives are protected, double underscore variables, function representatives are private.
he.py
#Coding=utf-8#defining the Grandfather classclassGrandfather:__uid1=1#Defining private Variables_uid2=2#Defining protection VariablesUid=3#Define public variables (you can access without creating class instances) #Defining Constructors def __init__(self):Pass #Defining public methods defgetUid1 (self):returnSelf.__uid1 #Defining protection Methods def_getuid2 (self):returnSelf._uid2#defining the Father class, inheriting the grandfather classclassFather (grandfather):#Defining Constructors def __init__(self): Grandfather.__init__(self)#overriding protection methods in grandfather def_getuid2 (self): Self._uid2=4returnSelf._uid2
Calling code:
Python 3.6.1 (V3.6.1:69C0DB5, Mar, 17:54:52) [MSC v.1900 + bit (Intel)] on Win32
Type "Copyright", "credits" or "license ()" For more information.
>>> from He Import *
>>> F=father ()
>>> print (F.getuid2 ())
4
>>> from He Import *
>>> F=father ()
>>> print (F.getuid2 ())
4
>>> print (F.GETUID1 ())
1
>>>
Object-oriented Python basics