fork download
  1. import types
  2.  
  3. class A():
  4. def __init__(self):
  5. self.value = 'hui'
  6.  
  7. def method1(self):
  8. print(self.value)
  9.  
  10. @staticmethod
  11. def method3():
  12. print('sosi')
  13.  
  14. def test(self):
  15. print(self.value)
  16.  
  17. obj = A()
  18. obj.method2 = types.MethodType(test, obj)
  19. obj.method4 = test
  20.  
  21. print(obj.method1)
  22. print(obj.method2)
  23. print(obj.method3)
  24. print(obj.method4)
Success #stdin #stdout 0.04s 9236KB
stdin
Standard input is empty
stdout
<bound method A.method1 of <__main__.A object at 0x151a3ac96e80>>
<bound method test of <__main__.A object at 0x151a3ac96e80>>
<function A.method3 at 0x151a3ad06c80>
<function test at 0x151a3ad06ea0>