#类属性又称为静态变量,或者是静态数据,这些数据是他们所属的类对象绑定的,不依赖于任何类实例 class ChinesePeople: country = ‘china‘ def __init__(self,name): self.name = name def play_ball(self,ball): print ("%s 正在打 %s" %(self.name))def say_word(self,word): print ("%s 说 %s" %(self.name,word)) #查看类属性print (ChinesePeople.country)#修改类属性ChinesePeople.country = "CHINA"print ChinesePeople.country#删除类属性del ChinesePeople.country#增加类属性ChinesePeople.country = "china"ChinesePeople.location = "Asia"print (ChinesePeople.__dict__)
原文地址:https://www.cnblogs.com/wangyue0925/p/8979486.html
时间: 2024-11-09 03:51:48