About 560,000 results
Open links in new tab
  1. python - Meaning of @classmethod and @staticmethod for …

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

  2. What is the difference between @staticmethod and …

    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 …

  3. python - What is the purpose of class methods? - Stack Overflow

    Class methods are for when you need to have methods that aren't specific to any particular instance, but still involve the class in some way. The most interesting thing about them is that …

  4. Python class methods: when is self not needed - Stack Overflow

    Jun 25, 2017 · 17 What is self? In Python, every normal method is forced to accept a parameter commonly named self. This is an instance of class - an object. This is how Python methods …

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

    Sep 16, 2008 · See what the Python tutorial has to say on the subject of classes and class objects. @Steve Johnson has already answered regarding static methods, also documented …

  6. python - How can I access "static" class variables within methods ...

    In java, an entire class is compiled, making the namespace resolution real simple: any variables declared outside a method (anywhere) are instance (or, if static, class) variables and are …

  7. What is the purpose of the `self` parameter? Why is it needed?

    811 The reason you need to use self is because Python does not use special syntax to refer to instance attributes. Python decided to do methods in a way that makes the instance to which …

  8. oop - Private methods in Python - Stack Overflow

    Jun 19, 2013 · Python doesn't have the concept of private methods or attributes. It's all about how you implement your class. But you can use pseudo-private variables (name mangling); any …

  9. class - Difference between 'cls' and 'self' in Python classes? - Stack ...

    Why is cls sometimes used instead of self as an argument in Python classes? For example: class Person: def __init__(self, firstname, lastname): self.firstname = firstname self.

  10. How do I use a class method without passing an instance to it?

    Nov 26, 2024 · Functions related to a class but that do not require either a class or an instance should be static methods Functions that are related to a class, and will need the class for …