📜  静态方法与类方法 python 代码示例

📅  最后修改于: 2022-03-11 14:45:11.268000             🧑  作者: Mango

代码示例1
# With classmethods, the class of the object instance is
# implicitly passed as the first argument instead of self.

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()