def method (self)print(xdef method (self) print(xi ( method ( method (print(xnester(print('-'* in enclosing def (nester) hides enclosing (nesterlocal global rest and here' what happens when we reassign the same name at multiple stops along the wayassignments in the local scopes of both functions and classes hide globals or enclosing function locals of the same nameregardless of the nesting involvedx def nester() print(xclass cx print(xdef method (self)print(xprint(self xdef method (self) print(xself print(self xi ( method ( method (print(xnester(print('-'* hides global local class local hides nester'sc or (not scopedlocal in enclosing def (not in class!) inherited class local hides enclosing (nesternot classlocal hides class located in instance global rest most importantlythe lookup rules for simple names like never search enclosing class statements--just defsmodulesand built-ins (it' the legb rulenot clegb!in method for examplex is found in def outside the enclosing class that has the same name in its local scope to get to names assigned in the class ( methods)we must fetch them as class or instance object attributesvia self in this case believe it or notwe'll see use cases for this nested classes coding pattern later in this bookespecially in some of ' decorators in this rolethe enclosing function usually both serves as class factory and provides retained state for later use in the enclosed class or its methods namespacesthe conclusion