标签:name init sel python 查看类 增删改 ict 类对象 country
#类属性又称为静态变量,或者是静态数据,这些数据是他们所属的类对象绑定的,不依赖于任何类实例
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__)
标签:name init sel python 查看类 增删改 ict 类对象 country
原文地址:https://www.cnblogs.com/wangyue0925/p/8979486.html