wangyue0925
#类属性又称为静态变量,或者是静态数据,这些数据是他们所属的类对象绑定的,不依赖于任何类实例

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__)

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-02-09
  • 2022-02-17
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-02-09
  • 2022-02-12
  • 2022-01-06
相关资源
相似解决方案