import types class A(): def __init__(self): self.value = 'hui' def method1(self): print(self.value) @staticmethod def method3(): print('sosi') def test(self): print(self.value) obj = A()obj.method2 = types.MethodType(test, obj)obj.method4 = test print(obj.method1)print(obj.method2)print(obj.method3)print(obj.method4)
Standard input is empty
<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>
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!