a = 1
b = 1
c = a + b
print(c)
# prints 2
a = 2
print(c)
# still prints 2, because that's how variables work
Is there something that looks clean, doesn’t waste RAM, and works like the following?
a = 1
b = 1
alias c = a + b
print(c)
# prints 2
a = 2
print(c)
# prints 3
or…
a = 1
b = 1
with a + b as c:
print(c) # prints 2
a = 2
print(c) # prints 3
In other words, can you alias something like a + b?
I am aware that, aside from readability, this is useless, but readability counts!
I also tried the example with with, but got AttributeError: __enter__.
In Python, everything is stored in memory, regardless if it’s assigned to a variable or not, whether it’s a number, lambda function or some other new language construct to store expressions.
You’ll find that even 100,000 lambda functions in an array is insignificant compared to a single Chrome tab