R

Ram Sharma • 3.40K Points
Extraordinary

Q. What will be printed?

Code:
def f():
x = 1

x = 5
f()
print(x)
  • (A) 1
  • (B) 5
  • (C) Error
  • (D) None
  • Correct Answer - Option(B)
  • Views: 30
  • Filed under category Python
  • Hashtags:

Explanation by: Ram Sharma

The variable `x` inside the function is local and does not affect the global variable `x = 5`.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.