1. 程式人生 > >類屬性的增刪改查

類屬性的增刪改查

per epp print init color span nbsp play del

 1 class People:
 2     def __init__(self,name,age,gender):   #self其實就是指自己,也就是下面調用的那個a1
 3         self.name = name
 4         self.age = age
 5         self.gender = gender
 6     person=人類
 7     def eat(self):
 8         print(%s對吃很有研究 %self.name)
 9     def sleepp(self):
10         print(%s對睡覺也很有研究
%self.name) 11 a1 = People(stt,18,male) 12 # 類屬性的增刪改查 13 # 14 def play(self): 15 print(%s對玩也很有研究 %self) 16 People.play = play 17 People.gender = male 18 print(People.__dict__) 19 People.play(stt) #stt對玩也很有研究 20 21 # 22 del People.gender 23 print(People.__dict__) 24 25 #
26 People.gender = female 27 def sleepp(self): 28 print(%s愛睡覺皮膚好好 %self.name) 29 People.sleepp = sleepp 30 a1.sleepp() #stt對睡覺也很有研究 31 # 32 print(People.person)

類屬性的增刪改查