func( func in moduleresult= this module and the function it contains use number of names to do their business using python' scope ruleswe can classify the names as followsglobal namesxfunc is global because it' assigned at the top level of the module fileit can be referenced inside the function as simple unqualified variable without being declared global func is global for the same reasonthe def statement assigns function object to the name func at the top level of the module local namesyz and are local to the function (and exist only while the function runsbecause they are both assigned values in the function definitionz by virtue of the statementand because arguments are always passed by assignment the underlying rationale for this name-segregation scheme is that local variables serve as temporary names that you need only while function is running for instancein the preceding examplethe argument and the addition result exist only inside the functionthese names don' interfere with the enclosing module' namespace (or any other functionfor that matterin factlocal variables are removed from memory when the function call exitsand objects they reference may be garbage-collected if not referenced elsewhere this is an automaticinternal stepbut it helps minimize memory requirements the local/global distinction also makes functions easier to understandas most of the names function uses appear in the function itselfnot at some arbitrary place in module alsobecause you can be sure that local names will not be changed by some remote function in your programthey tend to make programs easier to debug and modify functions are self-contained units of software the built-in scope we've been talking about the built-in scope in the abstractbut it' bit simpler than you may think reallythe built-in scope is just built-in module called builtinsbut you have to import builtins to query built-ins because the name builtins is not itself built in noi' seriousthe built-in scope is implemented as standard library module named builtins in xbut that name itself is not placed in the built-in scopeso you have to import it in order to inspect it once you doyou can run dir call to see which names are predefined in python (see ahead for usage)import builtins dir(builtins['arithmeticerror''assertionerror''attributeerror''baseexception''blockingioerror''brokenpipeerror''buffererror''byteswarning'python scope basics