3 ms·
A very common pattern in python is to declare all instance variables of a class in the __init__ method by setting them to None. This is done for * code readabi
by abdullahkhalids 4y ago
A very common pattern in python is to declare all instance variables of a class in the __init__ method by setting them to None. This is done for
* code readability; all relevant variables are in one place
* Python is a prototyping language, and a very common usage pattern is doing dir(object) to determine the names of all variables that could be set to something.
- joshuamorton 4y agoThis is no longer needed with modern python, you can use class Foo: my_int: int To handle this. That said, for the second case, a variable that may be set to something but may not be is optional! That's correct behavior!