Python Scopes BasicsScopes OverviewName Resolution: The LEGB RuleScopes ExamplesThe Built-in ScopeThe global StatementProgram Design: Minimize Global VariablesProgram Design: Minimize Cross-File ChangesOther Ways to Access GlobalsNested Functions and ScopesNested Scopes OverviewNested Scopes ExamplesClosures and Factory FunctionsArbitrary Scope NestingThe nonlocal Statementnonlocal Basicsnonlocal in Actionnonlocal Boundary CasesState-Retention OptionsNonlocals: Changeable, Per-Call, LEGBGlobals: Changeable but SharedFunction Attributes: Changeable, Per-Call, Explicit Classes: Changeable, Per-Call, OOPAnd the Winner Is…Scopes and Argument DefaultsLoops Require Defaults, Not ScopesChapter SummaryTest Your Knowledge: QuizTest Your Knowledge: Answers