About 241,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, while for …

  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 during object …

  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. 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 sense in the …

  7. How do I declare custom exceptions in modern Python?

    How do I declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instance) any extra string I include in the exc...

  8. 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 parentheses for …

  9. 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 …

  10. 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 capital letters …