class person(object):
def __init__(self,name,age):
self.name=name
self.age=age
laozhao=person('laozhao',29)
print(laozhao.name)
print(laozhao.age)
#给class 添加属性字段num
person.num=100
print(laozhao.num)#可以输出
laozhao.num2=200#
print(laozhao.num2)
def run():
print('...run....')
person.run=run#错误
#print(laozhao.run())
laozhao.run=run#可以输出 ...run...
print(laozhao.run())
import types#导入types
types.MethodType(run,person)#绑定函数run 到 person
print(laozhao.run())#可以输出..run..
'''
laozhao
29
100
200
...run....
None
...run....
None
'''