+ 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?

19th Mar 2018, 7:13 PM
Jon MĂ­kel Ibarreche Harfush
1 Answer
+ 4
there are two different x: global x is 5 inner x is 2 f() prines inner x print(x) prints global !
19th Mar 2018, 7:17 PM
Oma Falk
Oma Falk - avatar