About 604,000 results
Open links in new tab
  1. correct way to define class variables in Python - Stack Overflow

    I noticed that in Python, people initialize their class attributes in two different ways. The first way is like this: class MyClass: __element1 = 123 __element2 = "this is Africa" ...

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

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

  3. python class instance variables and class variables

    Feb 23, 2016 · I'm having a problem understanding how class / instance variables work in Python. I don't understand why when I try this code the list variable seems to be a class variable class testClass(): ...

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

    As a conclusion, never use class variables to set default values to object variables. Use __init__ for that. Eventually, you will learn that Python classes are instances and therefore objects themselves, which …

  5. python - What is the difference between class and instance variables ...

    The way Python knows which class to search for attributes that aren't found in the instance is by the hidden __class__ attribute. Which you can read to find out what class this is an instance of, just as …

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

  7. python - Proper way to create class variable in Data Class - Stack …

    May 21, 2020 · I've just begun playing around with Python's Data Classes, and I would like confirm that I am declaring Class Variables in the proper way. Using regular python classes class Employee:

  8. python - Getting the class name of an instance - Stack Overflow

    How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the inspect module or parse the __class__ attribute.

  9. difference between variables inside and outside of __init__() (class ...

    Oct 8, 2009 · 374 Variable set outside __init__ belong to the class. They're shared by all instances. Variables created inside __init__ (and all other method functions) and prefaced with self. belong to …

  10. oop - Variable scopes in Python classes - Stack Overflow

    Declaring a variable in a class (outside of a function) : all class functions can access it (basically a public variable) This is like a static variable and can be called using the class name.