I have a global variable foo
. I am using a function to add a number (which is sent as parameter to the function) to foo
. The first time I call this function, it runs fine, but the second time I run this, it only gives me the sum of initial value of foo
and the number passed as parameter. I am new to python and following is my code.
foo = 5
def add_number_to_foo(num):
global foo
return foo + num
add_number_to_foo(5) # returns 10 which is fine
add_number_to_foo(6) # returns 11, I should have got 16
I am a newbie in python, please excuse me if the question is ignorant. Thanks.