Python - What is the output: shadow global variable?

Question

What is the output of the following code?

X = 'Test' 
def func(): 
    X = 'book2s.com!' 

func() 
print(X) 


Click to view the answer

Test

Note

Assigning the variable inside the function makes it a local and effectively hides the global of the same name.

The print statement finds the variable unchanged in the global (module) scope.

Related Quiz