I'm hoping to make a variable that changes when a value "in it" changes. That may sound confusing.
I'm new to Python, and I'm hoping to use this in future projects.
Here's an explanation. Say I have the variable foo and I want it to always be equal to bar plus three.
If I do
bar = 6
foo = bar+3
Then foo is equal to 9. But if I then do
bar = 5
Then foo is still 9. I'd like foo to be equal to 8, without executing
foo = bar+3
again. Is there anything I can do to make that happen?
Thanks.
EDIT: Thanks for the answers! I was already aware about how variables work. I guess using functions with return is the only way to do it.
+ 3without executing+ 3. You can hide it behind a class (look up object-oriented programming), but you will still be executing the same logic.