('spam'spam make new tester that starts at ('eggs'eggs my state information updated to ('bacon'bacon but ' is where it left offat each call has different state information in this sensepython' nonlocals are more functional than function locals typical in some other languagesin closure functionnonlocals are per-callmultiple copy data boundary cases though usefulnonlocals come with some subtleties to be aware of firstunlike the global statementnonlocal names really must have previously been assigned in an enclosing def' scope when nonlocal is evaluatedor else you'll get an error--you cannot create them dynamically by assigning them anew in the enclosing scope in factthey are checked at function definition time before either an enclosing or nested function is calleddef tester(start)def nested(label)nonlocal state state print(labelstatereturn nested nonlocals must already exist in enclosing defsyntaxerrorno binding for nonlocal 'statefound def tester(start)def nested(label)global state state print(labelstatereturn nested globals don' have to exist yet when declared this creates the name in the module now tester( ('abc'abc state secondnonlocal restricts the scope lookup to just enclosing defsnonlocals are not looked up in the enclosing module' global scope or the built-in scope outside all defseven if they are already therespam def tester()def nested()nonlocal spam must be in defnot the moduleprint('current='spamspam + the nonlocal statement in