'what is the exact perpose of Getter,setter and deleter in python?
I saw some tutorials. Using getter ans setter the change some information like emails or username on the go. But What is the real world example of these.
Solution 1:[1]
Getter and setter methods are responsible in object-oriented languages for encapsulating data. However, we know that in python there are no hidden variables. So the proposal of these methods are:
- Add validation logic around getting and setting a value.
- Avoid direct access to a class field, ie private variables cannot be accessed or modified directly by an external user.
However, it is important to pay attention to the implementation of these methods in python. The default implementation just creating the methods will not assign any relevant effects and that achieve the goals listed above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sanches |
