I have been trying to return a variable in a function in a variable and use it outside of it:
test = 0
def testing():
test = 1
return test
testing(
Because you declare test
in the function, it is not a global variable, thus, you can not access the variable test
you created in the function outside of it as they are different scopes
If you want to return test
to a variable, you have to do
result = testing()
print(result)
Or, you can also add a global
statement:
test = 0
def testing():
global test
test = 1
return test
testing()
print(test)
By the way, when doing a conditional statement, you don't need the brackets around the 1==1
:).