def callme():
print(x)
x=20
x=10
callme()
x = 10
is assigned globally(line-4), callme()
calls def callme():
executes first, then comes print(x)
, So it has to print 10
, because python doesn't knows that there exists a variable x=20
in the 3rd line. But these lines prints error.
def callme():
print(x)
x=10
callme()
But in this case, it prints 10
. because x
is defined as global
variable.
Can anyone clarify this?