R

Ram Sharma • 3.40K Points
Extraordinary

Q. What will this code print?

Code:
def outer():
x = 'local'
def inner():
print(x)
inner()

outer()
  • (A) local
  • (B) global
  • (C) inner
  • (D) Error
  • Correct Answer - Option(A)
  • Views: 8
  • Filed under category Python
  • Hashtags:

Explanation by: Ram Sharma
The `inner()` function has access to variables from its enclosing scope (`x = 'local'`).

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.