6.1 (2) classes and objects

The following is a teacher Li Gang "crazy python handouts," the study notes

If infringement, delete the contact

 

Instance variables and class variables:

  Value after the visit by the nature of the object or class variables created by the class name to access the class variables, so when the class variable is changed, we will modify the read access time.

  Program to the class object created by variable assignment, then, is in fact redefined the instance variables of the new object, class variables will not be affected.

  

 

   

 

On the use of property function defined attributes, you can not read? ? ? ? ? ? ? ?

Hiding and encapsulation, can not read? ? ? ? ? ? ?

 

Class inheritance:

Inheritance syntax:

    subclass name class (parent class name1, parent name2 ,,):

      Class definition part

    The so-called sub-class inherits the parent class, meaning the subclass has all the functionality of the parent class.

    When a plurality of parent classes inherit, subclasses, and if more than one parent class contains instances of the same name of the method, the priority is: subclass, a parent, the parent class 2 .. . .

    Rewriting parent is in fact redefined in subclasses of the parent class instance.

    Call the overridden parent class method: using an unbound method call

                 

 

        

 

     I think it should be, because the instance of the parent class and not really overwritten

  The method of using the constructor function calls the parent super class:

    When a subclass inherits more than one parent class, if the parent class defines its own constructor, in fact, a subclass inherits only the first constructor of the parent class

    

 

The method of adding the class body:

     

 

     

 

 Limit dynamically added to a class property or method __slots__

    

 

 

 

Behind the complex is good, and so used a look at it later? ? ? ? ? ?

    

 

      

Guess you like

Origin www.cnblogs.com/tangmixun/p/12389932.html