0
Help again again
How does @property work in python
4 ответов
+ 4
Maybe it helps if we ask the question what's the point of properties.
After all, we can also simply create an instance variable, like this.
class Pet:
def __init__(self, name):
self.name = name
cat = Pet('Tom')
print(cat.name)
Python gives you a lot of freedom when you mess with the fields and attibutes of an object. It is difficult or impossible to block the user from changing some value.
In classical OOP languages (like C++, Java or C#) encapsulation is a very important concept. This means that you only allow the user of your code to see or change only certain aspects of your objects. Typically this happens by defining getter and setter methods, which control how a particular field can be read or written.
With property decorator you can achieve something similar in Python. This gives the developer some control over how the object's internal data can be consumed by other code.
+ 2
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-property/
You can also find it in the Python Intermediate course, OOP lesson.
+ 2
Podle Playz https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2472/?ref=app
Hope it's helpful to you
+ 1
Tibor Santa Still, Its very confusing to me