Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

staticmethod vs classmethod python

# 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()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #staticmethod #classmethod #python
ADD COMMENT
Topic
Name
8+7 =