What will be the output of the following Python code?
x = 50
def func():
global x
print('x is', x)
x = 2
print('Changed global x to', x)
func()
print('Value of x is', x)
x = 50
def func():
global x
print('x is', x)
x = 2
print('Changed global x to', x)
func()
print('Value of x is', x)A. x is 50
Changed global x to 2
Value of x is 50
B. x is 50
Changed global x to 2
Value of x is 2
C. x is 50
Changed global x to 50
Value of x is 50
D. None of the mentioned
Answer: Option B

Join The Discussion