Python: Unexpected behaviour of nonlocal variable in recursion
Python: Unexpected behaviour of nonlocal variable in recursion Question: The following code is expected to set the nonlocal variable flag to true after 3 calls to recur(). I expect flag in the following code to be always true after recur(2) returns (starting from 0) def f(): flag = False def recur(n): nonlocal flag print(f"this is …