I' am a beginner in python language. I've got a headache in understanding how global variables work. this is a specific example that doesn't make sense to me:
def func():
def nested():
global x
x=1
print(x)
func()
this throws :global name 'x' is not defined
Why is x is not available even though it has been made global in the nested function?
xis only defined in a function you never call, but you try to print it. Try callingnested()before printing and the global will get defined.nestedis never called anywhere.