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 '修改函数属性'