Programmers coming from other languages (particularly Java and C++) can try to make all attributes private and write extensive getter and setter functions. This kind of design pattern can be necessary for languages where type definitions are statically compiled into the runtime. It is not necessary in Python. Python depends on a different set of common patterns.
In Python, it's common to treat all attributes as public. This means the following:
- All attributes should be well documented.
- Attributes should properly reflect the state of the object; they shouldn't be temporary or transient values.
- In the rare case of an attribute that has a potentially confusing (or brittle) value, a single leading underscore character (_) marks the name as not part of the defined interface. It's not technically private, but it can't be relied on in the...