Returning Variables in Functions Python Not Working Right

You are messing up a bit the scopes and/or assignment. Try this:

def testing():
    test = 1
    return test

test = testing()
print(test)

Explanation: The test inside testing is different to the test inside the module. You have to assign it on module-level to get the expected result.

Leave a Comment