Addition, deletion, modification and inspection of attributes such as Python

#Class attributes are also called static variables, or static data. These data are bound to the class object to which they belong, and do not depend on any class instance 

. class ChinesePeople:
country = 'china' def __init__( self,name): self. name = name def play_ball( self, ball): print ( "%s is playing %s" %( self.name )) def say_word(self,word): print ( "%s says %s" %(self.name ,word)) #View the class attribute print (ChinesePeople.country) #Modify the class attribute ChinesePeople.country = "CHINA" print ChinesePeople.country #Delete the class attribute del ChinesePeople.country #Add the class attribute ChinesePeople.country = "china" ChinesePeople. location = "Asia"

















print (ChinesePeople.__dict__)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325121342&siteId=291194637