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 '修改函數屬性'