标签:ball name python self Chinesepeople -- person1 print 属性
# 类属性的增删改查 import time class Chinesepeople: country = 'China' person_type = '人' def __init__(self, name): self.name = name def play_ball(self, ball): print('%s正在玩%s' % (self.name, ball)) def eat_foot(self, foot): print('%s正在吃%s' % (self.name, foot)) # 查看类属性 print(Chinesepeople.country) # 修改类属性 Chinesepeople.country = 'CHINA' print(Chinesepeople.country) # 增加类属性 Chinesepeople.time_now = time.asctime() # 删除类属性 print(Chinesepeople.__dict__) del Chinesepeople.person_type print(Chinesepeople.__dict__) person1 = Chinesepeople('jack') person1.play_ball(ball='ball') print(person1.time_now)
# 实例属性的增删改查 class Chinese: def __init__(self, name): self.name = name def play_ball(self, ball): print('%s正在完%s' % (self.name, ball)) person1 = Chinese('alex') # 查看 print(person1.name) # 增加 person1.age = 18 print(person1.age) # 修改 person1.age = 20 print(person1.age) print(person1.__dict__) # 删除 del person1.age print(person1.__dict__)
标签:ball,name,python,self,Chinesepeople,--,person1,print,属性 来源: https://www.cnblogs.com/longloved/p/15106561.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。