Bound method object

Class methods are bound method objects by default

It special is that,

When the object will automatically call the function object itself passed as the first argument

When using the class name to call him is a normal function, there are several parameters have to pass a few parameters

Contact class

class Teacher: 
    School = " Old Boy " 
    DEF  __init__ (Self, name, the HP, GJ,):                                  # result is a memory address <. __ main __ Teacher Object AT 0x0000027C1B18FC18> 
        self.name = name 
        self.hp = the HP 
        self.gj = GJ 

    DEF Jineng (Self):
          Print (F " name {self.name} blood {self.hp}} self.gj attack { " ) 

RES = Teacher ( " Yang Xin " , 100,10 ) 
res.jineng ( ) 

RES = Teacher (" Bong " , 10,2 ) 
res.jineng () 
RES = Teacher ( " Gang " , 200, 10 ) 
res.jineng ()

 

Guess you like

Origin www.cnblogs.com/yangxinpython/p/11240511.html
Recommended