in python, what's the difference between using @property and using __variable for read-only? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

in python, what's the difference between using @property and using __variable for read-only?

14th Oct 2019, 9:17 PM
Lucho 23
Lucho 23 - avatar
2 Answers
0
@property allows you to write something like this: instance.attribute = whatever. Which looks like you're assigning something, but in the background, something completely different happens (keyword: encapsulation). I don't know exactly the relation you see with __-attributes. Can you explain a bit more?
14th Oct 2019, 10:28 PM
HonFu
HonFu - avatar
0
nvm i tested it and those are completly different things, thank you
14th Oct 2019, 10:29 PM
Lucho 23
Lucho 23 - avatar