def flipflop(p=False): p = not p def ret(): nonlocal p p = not p return p return ret fl = flipflop() print(fl()) print(fl()) print(fl()) print(fl())