python note 23 combinations

1, take the initiative to call the other members of the class

method one

class Base (Object):
     DEF F1 (Self):
         Print ( ' . 5 functions ' ) 


class Foo (Object):
     DEF F1 (Self):
         Print ( ' . 3 functions ' ) 
        Base.f1 (Self) 


obj = Foo ( ) 
obj.f1 () 

summary: 
. Base instance method (transfer own self) 
and inherited nothing to do

 

Second way

# ########### way: the order of succession according to the class, to find the next one. 
Class Foo (Object):
     DEF F1 (Self): 
        Super () F1 (). 
        Print ( ' . 3 functions ' ) 

class Bar (Object):
     DEF F1 (Self):
         Print ( ' . 6 functions ' ) 


class Info (Foo, Bar):
     Pass 

# obj = Foo () 
# obj.f1 () 

obj = Info () 
obj. f1 ()

 

Guess you like

Origin www.cnblogs.com/P-Z-W/p/11029470.html