class A(object): def foo(self, x): print(f"executing foo({self}, {x})") @classmethod def class_foo(cls, x): print(f"executing class_foo({cls}, {x})") @staticmethod def static_foo(x): print(f"executing static_foo({x})") a = A() a.foo(1) # executing foo(__main__ .a="" 0xb7db="" at="" object="", 1) a.class_foo(1) # executing class_foo(class main__.a="", 1) A.class_foo(1) # executing class_foo(class main__.a="", 1) a.static_foo(1) # executing static_foo(1) A.static_foo('hi') # executing static_foo(hi)
參考資料
沒有留言:
張貼留言