1. How to use the class
# First Define Class Luffystudent (): School = "Luffycity" # Data attribute def learn (self): # Function Property Print ("Is learning ...") def sleep (self): # Function Property Print ("Is sleeping ...") # View the namespace of the class print (luffystudent.__dict__) # {' __module__ ': ' __main__ ', ' School ': ' luffycity ', ' learn ': <function Luffystudent.learn at 0x00000000025b8b70> ' Sleep ': <function Luffystudent.sleep at 0x00000000025b8bf8>, ' __dict__ ': <attribute ' __dict__ ' of ' luffystudent ' objects>, ' __ weakref__ ': <attribute ' __weakref__ ' of ' luffystudent ' objects>, ' __doc__ ': None}print (luffystudent.__dict__[) School "]) # Luffycityprint (luffystudent.__dict__[" Learn "]) # <function Luffystudent.learn at 0x00000000025b8b70 ># Check Print (luffystudent.school) # luffycityprint (luffystudent.learn) # <function Luffystudent.learn at 0x0000000002158ae8># luffystudent.country = "China" Print (luffystudent.country) # china# Delete del Luffystudent.countryprint (luffystudent.__dict__) # {' __module__ ': ' __main__ ', ' School': ' luffycity ', ' learn ': <function Luffystudent.learn at 0x0000000002158ae8>, ' Sleep ': <function Luffystudent.sleep at 0x0000000002158b70>, ' __dict__ ': <attribute ' __dict__ ' of ' luffystudent ' objects>, ' __ weakref__ ': <attribute ' __weakref__ ' of ' luffystudent ' objects>, ' __doc__ ': none}# change luffystudent.school = "Foguang University "Print (luffystudent.__dict__) # {' __module__ ': ' __main__ ', ' School ': ' Foguang University ', ' Learn ': < function Luffystudent.learn at 0x0000000002158ae8>, ' Sleep ': <function luffystudent.sleep at 0x0000000002158b70 , ' __dict__ ': <attribute ' __dict__ ' of ' luffystudent ' objects>, ' __weakref__ ': <attribute ' __weakref__ ' of ' Luffystudent ' objects>, ' __doc__ ': None}
To be Continued ...
python-Object-oriented