v = 0 # global variable def a(): def test(n): nonlocal m # used in nested function whose local scope is not defined global v # outside of function or in global scope if n == 5: return n t = test(n + 1) # local variable m += t + n v += t + n return n + t m = 0 test(1) print(m) a()