Does the evaluation of variables in print
and f-string happen at different times?
I expected it to be the same output for both.
def foo(x):
x.append([5])
return x
y, z = [1], [3]
print('y:', y, 'z:', z)
# y: [1] z: [3]
print('y:', y, 'str(y):', str(y), 'foo(y):', foo(y))
# y: [1, [5]] str(y): [1] foo(y): [1, [5]]
print(f'z: {z} foo(z): {foo(z)} z: {z}')
# z: [3] foo(z): [3, [5]] z: [3, [5]]
Can someone explain what is happening?