which follow the same legb scope lookup rule as function definitions this rule applies both to the top level of the class itselfas well as to the top level of method functions nested within it both form the layer in this rule--they are normal local scopeswith access to their namesnames in any enclosing functionsglobals in the enclosing moduleand built-ins like modulesthe class' local scope morphs into an attribute namespace after the class statement is run although classes have access to enclosing functionsscopesthoughthey do not act as enclosing scopes to code nested within the classpython searches enclosing functions for referenced namesbut never any enclosing classes that isa class is local scope and has access to enclosing local scopesbut it does not serve as an enclosing local scope to further nested code because the search for names used in method functions skips the enclosing classclass attributes must be fetched as object attributes using inheritance for examplein the following nester functionall references to are routed to the global scope except the lastwhich picks up local scope redefinition (the section' code is in file classscope pyand the output of each example is described in its last two comments) def nester()print(xclass cprint(xdef method (self)print(xdef method (self) print(xi ( method ( method (print(xnester(print('-'* global global global hides global local global rest watch what happensthoughwhen we reassign the same name in nested function layersthe redefinitions of create locals that hide those in enclosing scopesjust as for simple nested functionsthe enclosing class layer does not change this ruleand in fact is irrelevant to itx def nester() print(xclass cprint( class coding details hides global local in enclosing def (nester)