Python - What is the output: global reassignment?

Question

What is the output of the following code?

X = 'Test' 
def func(): 
    X = 'test' 
    print(X) 

func() 
print(X) 


Click to view the answer

test
Test

Note

The reference to the variable within the function finds the assigned local and the reference in the print statement finds the global.

Related Quiz