R

Ram Sharma • 3.40K Points
Extraordinary

Q. What will the following code output?

Code:
def f():
global x
x = 10

f()
print(x)
  • (A) Error
  • (B) 0
  • (C) 10
  • (D) None
  • Correct Answer - Option(C)
  • Views: 14
  • Filed under category Python
  • Hashtags:

Explanation by: Ram Sharma
`x` is declared global inside the function, so it's available in the global scope after calling `f()`.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.