The other answers already say that you never need getters in Python, and it's just a matter of style.
But the key here is that there is a Pythonic style, and unnecessary getters go against that style. Using unnecessary getters will raise red flags when experienced Python developers read your code. (How many seconds did it take to get three comments saying variations of "Someone used Java too much" here?)
If you read the PEP 8 style guide, under Designing for inheritance, it says:
For simple public data attributes, it is best to expose just the attribute name, without complicated accessor/mutator methods. Keep in mind that Python provides an easy path to future enhancement, should you find that a simple data attribute needs to grow functional behavior. In that case, use properties to hide functional implementation behind simple data attribute access syntax.
PEP 8 is only intended as a style guide for the stdlib, but it's still generally considered a good description of what idiomatic Python looks like ("TOOWTDI" means any descriptive guide is implicitly a prescriptive guide, at least in theory), and there are nice testers and fixers that let you test your own code against PEP 8 guidelines.
While I'm at it, William's answer linked to why use getters and setters, a language-agnostic question, where the accepted answer is a list of reasons why accessors are sometimes a good idea. Almost none of them are relevant to Python. Most can be answered with one word: @property
(or, in the last case, attrgetter
). For the rest:
- Controlling the lifetime and memory management… Python has managed memory.
- Providing a debugging interception point… Interpreted languages make it easy to place watchpoints while debugging.
- Improved interoperability with libraries… Python's
mock
, pickle
, etc. are designed to operate with attributes.
- Allowing inheritors to change the semantics of how the property behaves and is exposed by overriding the getter/setter methods. This is only relevant for languages with static typing except for virtual functions, like C++ or Java.