By accessing the object class attributes and methods

. 1  class the Person ():
 2      name = " Baby " 
. 3      Age = 0
 . 4      DEF eatFood (Self):
 . 5          Print ( " EAT --- Food " )
 . 6      DEF SLEEP (Self):
 . 7          Print ( " rainy day, sleeping days " )
 . 8      DEF Shopping (Self, Money):
 . 9          Print ( " shopping spent membered% s " % Money)
 10  
. 11  # by creating class instance object 
12 is PER1 =The Person ()
 13 is  '' ' 
14  by way of example in the property class object access:
 15  Format:
 16  Value: object name attribute names
 17  assigned: the new object name attribute name = value
 18 is  ' '' 
. 19  Print (per1.name )   # Baby 
20 is per1.name = " John Doe " 
21 is  Print (per1.name)   # seating 
22 is  Print (per1.age)    # 0 
23 is  
24  '' ' 
25  by way of example a method in the class object access / behavioral / functions:
 26  format:
 27  . Object name function name ([argument list])
 28  Note: in the class, the first parameter is the default self, when an instance of the object class function call
 29 When the number, the default will be the current object to the self parameter, we called and executed function,
 30  do not have to re-transmission of argument (the system has the argument to the self).
31 is  ' '' 
32  per1.eatFood ()
 33 is  
34 is Per2 = the Person ()
 35  Print (per2.name)    # Baby 
36  per2.sleep ()
 37 [  
38 is per2.shopping (12 is )
 39  
40 per1.shopping (34 is)

 

Guess you like

Origin www.cnblogs.com/BKY88888888/p/11272365.html