1. 给实现对象添加方法
import types
class Person(object):
def __init__(self, newName, newAge):
self.name = newName
self.age = newAge
def eat(self):
print("————%s正在吃" %self.name)
def run(self): #动态的方法
print("————%s正在跑" % self.name)
P = Person("p2",20)
p1 = Person("p1",10)
p1.eat()
p1.run = types.MethodType(run,p1)
p1.run()
2. 100多本Python书,免费哟
https://blog.csdn.net/dQCFKyQDXYm3F8rB0/article/details/84901260