About 237,000 results
Open links in new tab
  1. 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...

  2. 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" ...

  3. Elegant ways to support equivalence ("equality") in Python classes

    Python 3 has only new-style classes that are declared as class A:, class A(object): or class A(B):. For classic-style classes, a comparison operation always calls the method of the first operand, …

  4. python - How to force/ensure class attributes are a specific type ...

    Mar 29, 2020 · In Python, primitive data types (int, float, str, booleans) are themselves classes. Thus if you instantiate the class attributes of your class before passing the method parameters …

  5. Define a method outside of class definition? - Stack Overflow

    May 26, 2018 · You can define a function outside of a class and then add it. However, there is a subtle difference in assigning the function to the class or to the instance object.

  6. Python class definition syntax - Stack Overflow

    The parentheses in class definitions are for defining from which class you inherit. You don't write def in front of it, and when you inherit from 'object' which is the default you don't need the …

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

    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 …

  8. How can I dynamically create class methods for a class in python

    81 You can dynamically add a classmethod to a class by simple assignment to the class object or by setattr on the class object. Here I'm using the python convention that classes start with …

  9. Is there a benefit to defining a class inside another class in Python?

    Sep 17, 2008 · I don't know Python, but your question seems very general. Ignore me if it's specific to Python. Class nesting is all about scope. If you think that one class will only make …

  10. python - How to make a class property? - Stack Overflow

    In python I can add a method to a class with the @classmethod decorator. Is there a similar decorator to add a property to a class? I can better show what I'm talking about. class …