+ 1
Variable values after function
x=5 def f() x=2 print (x) f() print (x) Get this output: 2 5 Why "x" value is not 2 at the end?
1 Answer
+ 4
there are two different x:
global x is 5
inner x is 2
f() prines inner x
print(x) prints global !
x=5 def f() x=2 print (x) f() print (x) Get this output: 2 5 Why "x" value is not 2 at the end?