0

Can someone please explain this to me?

Variable = 9 Def function(variable): Variable += 1 Print (variable) Function (7) Print (variable) Answer: 8 9

19th Jul 2020, 7:04 PM
A.13S.
6 Answers
+ 4
Thank you all!
19th Jul 2020, 7:39 PM
A.13S.
+ 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)
19th Jul 2020, 7:25 PM
madeline
madeline - avatar
+ 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
19th Jul 2020, 7:32 PM
BroFar
BroFar - avatar