state to be accessed externallyand saves line by not requiring nonlocal declarationdef tester(start)def nested(label)print(labelnested statenested state + nested state start return nested tester( ('spam'spam ('ham'ham state nested is in enclosing scope change attrnot nested itself initial state after func defined is 'nestedwith state attached can access state outside functions too because each call to the outer function produces new nested function objectthis scheme supports multiple copy per-call changeable data just like nonlocal closures and classes-- usage mode that global variables cannot provideg tester( ('eggs'eggs ('ham'ham has own statedoesn' overwrite ' state state is false state is accessible and per-call different function objects this code relies on the fact that the function name nested is local variable in the tester scope enclosing nestedas suchit can be referenced freely inside nested this code also relies on the fact that changing an object in place is not an assignment to namewhen it increments nested stateit is changing part of the object nested referencesnot the name nested itself because we're not really assigning name in the enclosing scopeno nonlocal declaration is required function attributes are supported in both python and xwe'll explore them further in importantlywe'll see there that python uses naming conventions in both and that ensure that the arbitrary names you assign as function attributes won' clash with names related to internal implementationmaking the namespace equivalent to scope subjective factors asidefunction attributesutility does overlap with the newer nonlocal in xmaking the latter technically redundant and far less portable scopes