标签:pre pytho run object class obj type types imp
1 class Person(object): 2 def __init__(self,name,age): 3 self.name = name 4 self.age =age 5 def eat(self): 6 print(‘----%s正在吃饭------‘ % self.name) 7 8 def run(self): 9 print(‘-----%s-----‘%self.name) 10 11 #如何将run添加到Person类的一个实例对象中呢? 12 实例化类 13 xiaoming = Person(‘xm‘,18) 14 import type 15 xiaoming.run = types.MethodType(run,xiaoming) 16 # 运行即将run方法添加到了实例对象xiaoming中 17 xiaoming.run()
标签:pre pytho run object class obj type types imp
原文地址:https://www.cnblogs.com/houzichiguodong/p/9172781.html