+ 2
which approach is most efficient for design a program in Python: property function or property decorator?
2 Answers
+ 1
Property function and property decorator do the exact same thing. They provide a way to define custom behavior or rules when a class attribute is retrieved (get) or changed (set).
While this is the norm of encapsulation in many OOP languages, python is a bit different because you cannot really hide the internal workings of a class, technically everything remains public. So unless you really have to apply some special logic or restriction on the value of an attribute, it is not needed to implement getters and setters.
If you really must, then I think decorators are more pythonic :)
https://www.programiz.com/python-programming/property
0
Her... Aren't decorators a type of function? (or am I off track?)