assignments do for instanceif the name is assigned to list at the top level of modulea statement within function will classify as localbut append(xwill not in the latter casewe are changing the list object that referencesnot itself -- is found in the global scope as usualand python happily modifies it without requiring global (or nonlocaldeclaration as usualit helps to keep the distinction between names and objects clearchanging an object is not an assignment to name name resolutionthe legb rule if the prior section sounds confusingit really boils down to three simple rules with def statementname assignments create or change local names by default name references search at most four scopeslocalthen enclosing functions (if any)then globalthen built-in names declared in global and nonlocal statements map assigned names to enclosing module and function scopesrespectively in other wordsall names assigned inside function def statement (or lambdaan expression we'll meet laterare locals by default functions can freely use names assigned in syntactically enclosing functions and the global scopebut they must declare such nonlocals and globals in order to change them python' name-resolution scheme is sometimes called the legb ruleafter the scope nameswhen you use an unqualified name inside functionpython searches up to four scopes--the local (lscopethen the local scopes of any enclosing (edefs and lambdasthen the global (gscopeand then the built-in (bscope--and stops at the first place the name is found if the name is not found during this searchpython reports an error when you assign name in function (instead of just referring to it in an expression)python always creates or changes the name in the local scopeunless it' declared to be global or nonlocal in that function when you assign name outside any function ( at the top level of module fileor at the interactive prompt)the local scope is the same as the global scope-the module' namespace because names must be assigned before they can be used (as we learned in )there are no automatic components in this modelassignments always determine name scopes unambiguously figure - illustrates python' four scopes note that the second scope lookup layere--the scopes of enclosing defs or lambdas--can technically correspond to more than one lookup level this case only comes into play when you nest functions within functionsand is enhanced by the nonlocal statement in scopes