0
Can someone please explain this to me?
Variable = 9 Def function(variable): Variable += 1 Print (variable) Function (7) Print (variable) Answer: 8 9
6 Answers
+ 4
Thank you all!
+ 1
the first âvariableâ is global scope, the second one (in the function) is local. function(7) uses the local variable to make 8. print(variable) prints the global one, which is just 9
ps: if you wanted to combine them try this... and see
variable = 9
def function():
global variable
variable += 1
print(variable)
print(function())
print(variable)
+ 1
variable = 9
def function(variable):
variable += 1 ## 7 + 1 = 8
print (variable , "local")
function (7)
print (variable, "global") ## 9
## Answer: 8 9
https://code.sololearn.com/cQHvP058gYh7/?ref=app