About 50 results
Open links in new tab
  1. python - What is the difference between class and instance attributes ...

    class B(object): def __init__(self, foo=5): self.foo = foo If you're creating a lot of instances, is there any difference in performance or space requirements for the two styles? When you read the code, do you …

  2. What is the difference between @staticmethod and @classmethod in …

    Sep 26, 2008 · What is the difference between a method decorated with @staticmethod and one decorated with @classmethod?

  3. How can I define a class in Python? - Stack Overflow

    Quite simple, I'm learning Python, and I can't find a reference that tells me how to write the following: public class Team { private String name; private String logo; private int m...

  4. python - 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 …

  5. Python __class__ () - Stack Overflow

    The parent-child relationships of the Python type system must stop somewhere, and type is that point. In your example, a.__class__ is a reference to the Foo class.

  6. class - What is the difference between objects and classes in Python ...

    Jun 30, 2024 · I was wondering what is the difference between objects and classes in python? I thought all classes are objects, but in that case, author wouldn't have used phrase "classes and objects".

  7. python - How to print instances of a class using print ... - Stack Overflow

    A simple decorator @add_objprint will help you add the __str__ method to your class and you can use print for the instance. Of course if you like, you can also use objprint function from the library to print …

  8. python - How do I set and access attributes of a class? - Stack Overflow

    Well, Python tries to get first the object variable, but if it can't find it, will give you the class variable. Warning: the class variable is shared among instances, and the object variable is not. As a …

  9. When should I be using classes in Python? - Stack Overflow

    Oct 12, 2015 · In python the simple heuristic for when you should use a class comes down to whether or not your abstraction needs to be concerned with state. Abstractions that carry mutable state should …

  10. python - How to add property to a class dynamically ... - Stack Overflow

    I know this is an old question, but here is a way to modify the source of a class and insert protected class variables and new class properties. The idea behind this is to dynamically modify the source …