In SML (a functional programming language that I learned before Python), I can do the following:
val x = 3;
fun f() = x;
f();
>>> 3
val x = 7;
f();
>>> 3
In Python, however, the first call will give 3 and the second one will give 7.
x = 3
def f(): return x
f()
>>> 3
x = 7
f()
>>> 7
How do I bind the value of a variable to a function in Python?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…