def generate(label)returns class instead of an instance class spamcount def method(self)print("% =% (labelspam count)return spam aclass generate('gotchas' aclass( method(gotchas= miscellaneous class gotchas here' handful of additional class-related warningsmostly as review choose per-instance or class storage wisely on similar notebe careful when you decide whether an attribute should be stored on class or its instancesthe former is shared by all instancesand the latter will differ per instance this can be crucial design issue in practice in gui programfor instanceif you want information to be shared by all of the window class objects your application will create ( the last directory used for save operationor an already entered password)it must be stored as class-level dataif stored in the instance as self attributesit will vary per window or be missing entirely when looked up by inheritance you usually want to call superclass constructors remember that python runs only one __init__ constructor method when an instance is made--the lowest in the class inheritance tree it does not automatically run the constructors of all superclasses higher up because constructors normally perform required startup workyou'll usually need to run superclass constructor from subclass constructor--using manual call through the superclass' name (or super)passing along whatever arguments are required--unless you mean to replace the super' constructor altogetheror the superclass doesn' have or inherit constructor at all delegation-based classes in x__getattr__ and built-ins another reminderas described earlier in this and elsewhereclasses that use the __getattr__ operator overloading method to delegate attribute fetches to wrapped objects may fail in python (and when new-style classes are usedunless operator overloading methods are redefined in the wrapper class the names of operator overloading methods implicitly fetched by built-in operations are not routed through generic attribute-interception methods to work around thisyou must redefine such class gotchas