I've stumbled on a piece of code which looks like this:
x = 12
def f1(a,b=x):
print(a,b)
x = 15
f1(4)
And in mind, I surely thought the answer is 4 15
since the call of the f1
is after I assign x
to 15
, when I ran it I got 4 12
.
Why does it not print out 4 15
since x
is 15
when I call f1
?
EDIT
x = 12
def f1(a,b=x):
print(x)
print(b)
print(a,b)
x = 15
f1(4)
Prints out
15
12
4 12
So the question becomes why b
is not being updated with the new value of x
?