About 51 results
Open links in new tab
  1. What is the difference between @staticmethod and @classmethod in …

    Sep 26, 2008 · static methods are sometimes better off as module level functions in python for the sake of cleanliness. With a module function it is easier to import just the function you need and prevent …

  2. Meaning of @classmethod and @staticmethod for beginner

    Aug 29, 2012 · Here we have __init__, a typical initializer of Python class instances, which receives arguments as a typical instance method, having the first non-optional argument (self) that holds a …

  3. python - Module function vs staticmethod vs classmethod vs no ...

    The idiomatic translation of a Java static method is usually a module-level function, not a classmethod or staticmethod. (And static final fields should translate to module-level constants.)

  4. Python : Difference between static methods vs class method

    Mar 16, 2012 · Possible Duplicate: What is the difference between @staticmethod and @classmethod in Python? I am learning OOP in python and came to know about these two methods It seems that the …

  5. Class method differences in Python: bound, unbound and static

    Sep 22, 2008 · If you want the equivalent of a static method you can use a class method. There's much less need for class methods in Python than static methods in languages like Java or C#.

  6. python - What is the purpose of static methods? How do I know when …

    True >>>RandomClass.static_method is RandomClass().static_method True 3.It improves code readability, signifying that the method does not depend on state of the object itself. 4.It allows for …

  7. python: When to use static method over class method?

    10 Based on what I read, class methods are largely the same as static methods with a few exceptions but have the advantage of providing a class pointer. As a result, is there really any reason to use …

  8. Static methods in Python? - Stack Overflow

    Apr 10, 2009 · class MyClass(object): def the_static_method(x): print(x) the_static_method = staticmethod(the_static_method) MyClass.the_static_method(2) # outputs 2 This is entirely identical …

  9. oop - Python: creating a class instance via static method vs class ...

    Feb 7, 2023 · print(dummy_instance_from_class.dict) > {'dummy_var': 124} What I often see in codes of other people is the classmethod design instead of staticmethod. Why is this the case? Or, rephrasing …

  10. python - Class (static) variables and methods - Stack Overflow

    Sep 16, 2008 · How do I create class (i.e. static) variables or methods in Python?