you can also see that there was no previous binding for spam before the global assignment first look at classes classes introduce little bit of new syntaxthree new object typesand some new semantics class definition syntax the simplest form of class definition looks like thisclass classnameclass definitionslike function definitions (def statementsmust be executed before they have any effect (you could conceivably place class definition in branch of an if statementor inside function in practicethe statements inside class definition will usually be function definitionsbut other statements are allowedand sometimes useful -we'll come back to this later the function definitions inside class normally have peculiar form of argument listdictated by the calling conventions for methods -againthis is explained later when class definition is entereda new namespace is createdand used as the local scope -thusall assignments to local variables go into this new namespace in particularfunction definitions bind the name of the new function here when class definition is left normally (via the end) class object is created this is basically wrapper around the contents of the namespace created by the class definitionwe'll learn more about class objects in the next section the original local scope (the one in effect just before the class definition was enteredis reinstatedand the class object is bound here to the class name given in the class definition header (classname in the exampleclass objects class objects support two kinds of operationsattribute references and instantiation attribute references use the standard syntax used for all attribute references in pythonobj name valid attribute names are all the names that were in the class' namespace when the class object was created soif the class definition looked like thisclass myclass""" simple example class"" def (self)return 'hello worldthen myclass and myclass are valid attribute referencesreturning an integer and function objectrespectively class attributes can also be assigned toso you can change the value of myclass by assignment __doc__ is also valid attributereturning the docstring belonging to the class" simple example class classes