staticmethod vs classmethod python

Solutions on MaxInterview for staticmethod vs classmethod python by the best coders in the world

showing results for - "staticmethod vs classmethod python"
Dido
27 May 2020
1# With classmethods, the class of the object instance is
2# implicitly passed as the first argument instead of self.
3
4class A(object):
5    def foo(self, x):
6        print(f"executing foo({self}, {x})")
7
8    @classmethod
9    def class_foo(cls, x):
10        print(f"executing class_foo({cls}, {x})")
11
12    @staticmethod
13    def static_foo(x):
14        print(f"executing static_foo({x})")
15
16a = A()
17