Study Notes (08): 21 days clearance Python (Video Lesson only) - class methods, and static methods

Learning immediately: https://edu.csdn.net/course/play/24797/282188?utm_source=blogtoedu

the Test class: 
    DEF the __init __ (Self, name = 'Test'): 
        the self.name name = 
        Print ( 'the init +' + name) 

    @classmethod 
    DEF testA (CLS): 
        Print ( 'testA') 

    @staticmethod 
    DEF testB (V) : 
        Print ( 'testB +' + V) 


# object invokes 
T = the Test () 
t.testA () 
# class calls 
Test.testA () 
Print ( "-" 30 *) 
# object invokes 
TT = the Test () 
tt.testB ( 'Val') 
# class calls 
Test.testB ( 'Val') 
Print ( "-" 30 *) 
# object invokes 
TTT = the Test () 
Print (ttt.name) 
# class to call 
the Test ( 'Val') name. 
' ''
            Examples of methods for class static method
Object calls automatically bound automatic binding does not automatically bound  
Class call does not automatically bound automatically bound not automatically bind 
'' '
Published 25 original articles · won praise 4 · Views 608

Guess you like

Origin blog.csdn.net/happyk213/article/details/105139755