I am trying to access a variable that I made inside of a function on the outside. This is what I did:
def add(a,b):
v = a + b
print(v)
add(5,5)
print(v)
However, it tells me that it is not defined when I try to print it outside of the function. I then proceeded to create the variable outside of the function first, and then change it inside of the function. This is what I did for that:
v = 0
def add(a,b):
v = a + b
print(v)
add(5,5)
print(v)
In this case, it just printed out 0 instead of 10 on the last line. Is there any way to keep the changes to variable while it was inside of the function instead of it staying the same?