类属性增删改查
程序员文章站
2022-03-26 12:09:33
dir同样可以查找实例的属性字典 print(dir(p1)) 下面是增删改查举例: class Chinese: country='中国' def __init__(self,name): self.name=name def play_ball(self,ball): print('%s正在打% ......
dir同样可以查找实例的属性字典
print(dir(p1))
下面是增删改查举例:
class chinese: country='中国' def __init__(self,name): self.name=name def play_ball(self,ball): print('%s正在打%s' %(self.name)) print(chinese.country) '查看’ chinese.country='russian' '修改' chinese.fuse='黄色' '增加' del chinese.fuse '删除‘ def eat_food(self,food): pass chinese.food=eat_food '增加函数属性’ def test(self): pass chinese.play_ball=test '修改函数属性'