What is the output of the following Python code snippet?
x = 5
def f():
x = 10
f()
print(x)
def f():
x = 10
f()
print(x)
Correct answer
C. 5
5 views
C. 5
5 views
Without global, assignment inside the function creates a local variable.
Asked in: Python Interview Functions
https://docs.python.org/3/tutorial/controlflow.html#defining-functionsNot sure why the answer is C? Ask here and get an explanation.