def double(n):
global y
y = 2 * n
y = 5
double(y)
print(y)
Confused with the output why is it 10 and not 5?
def double(n):
global y
y = 2 * n
y = 5
double(y)
print(y)
Confused with the output why is it 10 and not 5?
The global keyword allows a user to modify a variable outside of the current scope, so when use global y, y change outside of the function. if remove a global keyword the output will be 5.