July 4, 2019 Classes and Objects 1

d1 = class name () to instantiate

 

python2 carve Classic and new classes

Only new class python3

 

Attributes:

  1. The data attributes - variable

  2. property function is a function, generally referred to as object-oriented method

  Classes and method objects are by dots

class Chinese:
     ' chinese people class ' 
    Dang = ' the GCD '  # definitions properties 
    DEF sui_di_tu_tan (): # passing itself to parameter 
        Print ( ' spitting ' )
     DEF cha_dui (Self):
         Print ( ' into the front ' ) 


Print (Chinese.dang) # call the class 
Print (Chinese. __dict__ ) # attribute dictionary view class 
Chinese.sui_di_tu_tan ()
 Print (Chinese. __dict__ [ 'Dang ' ]) # Looking dictionary properties by way of 
Chinese. the __dict__ [ ' sui_di_tu_tan ' ] () # Looking properties, function attribute dictionary by way of brackets + 
Chinese.cha_dui ( ' XXXX ' ) # if you have to pass by the object Self 
P1 Chinese = () # bracketed is called instantiation, essentially the same return

》》》

The GCD
{ '__module__': '__main__', 'the __doc__': 'chinese people category', 'dang': 'GCD ', 'sui_di_tu_tan': <function Chinese.sui_di_tu_tan at 0x100768f28>, 'cha_dui': <function Chinese. cha_dui at 0x100768e18>, '__dict__' : <attribute '__dict__' of 'Chinese' objects>, '__weakref__': <attribute '__weakref__' of 'Chinese' objects>}
spitting
GCD
spitting
into the front

Guess you like

Origin www.cnblogs.com/python1988/p/11129236.html