1 class Person(): 2 def __init__(self, name): 3 self.name = name 4 5 6 def print_name(self): 7 print(self.name) 8 9 p = Person('Li')10 import types11 p.print_name = types.MethodType(print_name, p) # 绑定函数到对象12 p.print_name()13 14 15 @staticmethod16 def print_abc():17 print('abc')18 19 Person.print_abc = print_abc20 Person.print_abc()21 22 23 @classmethod24 def print_123(cls):25 print('123')26 27 Person.print_123 = print_12328 Person.print_123()