标签:span people print 调用 name self 属性 col ict
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)
标签:span people print 调用 name self 属性 col ict
原文地址:https://www.cnblogs.com/humanskin/p/9028574.html