Sail E0 Webinar
Question
What is the output of the below program?x = 50def func():    global x    print('x is', x)    x = 2    print('Changed global x to', x)func()print('Value of x is', x)
Options:
A .  x is 50Changed global x to 2Value of x is 50
B .  x is 50Changed global x to 2Value of x is 2
C .  x is 50Changed global x to 50Value of x is 50
D .  None of the mentioned
Answer: Option B


The global statement is used to declare that x is a global variable “ hence, when we assign a value to x inside the function, that change is reflected when we use the value of x in the main block.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers