options are availabledepending on your goals the next three sections present some alternatives some of the code in these sections uses tools we haven' covered yet and is intended partially as previewbut we'll keep the examples simple here so that you can compare and contrast along the way state with globalsa single copy only one common prescription for achieving the nonlocal effect in and earlier is to simply move the state out to the global scope (the enclosing module)def tester(start)global state state start def nested(label)global state print(labelstatestate + return nested tester( ('spam'spam ('eggs'eggs move it out to the module to change it global allows changes in module scope each call increments shared global state this works in this casebut it requires global declarations in both functions and is prone to name collisions in the global scope (what if "stateis already being used? worseand more subtleproblem is that it only allows for single shared copy of the state information in the module scope--if we call tester againwe'll wind up resetting the module' state variablesuch that prior calls will see their state overwritteng tester( ('toast'toast resets state' single copy in global scope ('bacon'bacon ('ham'ham but my counter has been overwrittenas shown earlierwhen you are using nonlocal and nested function closures instead of globaleach call to tester remembers its own unique copy of the state object state with classesexplicit attributes (previewthe other prescription for changeable state information in and earlier is to use classes with attributes to make state information access more explicit than the implicit magic of scope lookup rules as an added benefiteach instance of class gets fresh why nonlocalstate retention options