also support inheritancemultiple behaviorsand other tools we haven' explored classes in detail yetbut as brief preview for comparisonthe following is reformulation of the earlier tester/nested functions as classwhich records state in objects explicitly as they are created to make sense of this codeyou need to know that def within class like this works exactly like normal defexcept that the function' self argument automatically receives the implied subject of the call (an instance object created by calling the class itselfthe function named __init__ is run automatically when the class is calledclass testerdef __init__(selfstart)self state start def nested(selflabel)print(labelself stateself state + tester( nested('spam'spam nested('ham'ham class-based alternative (see part vion object constructionsave state explicitly in new object reference state explicitly changes are always allowed create instanceinvoke __init__ is passed to self in classeswe save every attribute explicitlywhether it' changed or just referencedand they are available outside the class as for nested functions and nonlocalthe class alternative supports multiple copies of the retained datag tester( nested('toast'toast nested('bacon'bacon each instance gets new copy of state changing one does not impact others nested('eggs'eggs state ' state is where it left off state may be accessed outside class with just slightly more magic--which we'll delve into later in this book--we could also make our class objects look like callable functions using operator overloading __call__ intercepts direct calls on an instanceso we don' need to call named methodclass testerdef __init__(selfstart)self state start def __call__(selflabel)print(labelself stateself state + tester( ('juice'juice scopes intercept direct instance calls so nested(not required invokes __call__