0
Python variables in order?
Is it not true that when you define a variable once, but then you define it again, that the variable will take the latest definition when it is called? For example, if I define x=1 but then afterward say x=2 and then print(x), won't it output 2 instead of 1?
2 ответов
+ 2
yes x should print 2 in that case
+ 1
Yes, except if you don't do the assignment in same scope:
def func():
x=2
x=1
print(x) # output 1
func()
print(x) # still output 1 ^^