spam spam numinstances and cannot be changed via inheritance because the class name is accessible to the simple function as global variablethis works fine alsonote that the name of the function becomes globalbut only to this single moduleit will not clash with names in other files of the program prior to static methods in pythonthis structure was the general prescription because python already provides modules as namespace-partitioning toolone could argue that there' not typically any need to package functions in classes unless they implement object behavior simple functions within modules like the one here do much of what instance-less class methods couldand are already associated with the class because they live in the same module unfortunatelythis approach is still less than ideal for one thingit adds to this file' scope an extra name that is used only for processing single class for anotherthe function is much less directly associated with the class by structurein factits definition could be hundreds of lines away perhaps worsesimple functions like this cannot be customized by inheritancesince they live outside class' namespacesubclasses cannot directly replace or extend such function by redefining it we might try to make this example work in version-neutral way by using normal method and always calling it through (or withan instanceas usualclass spamnuminstances def __init__(self)spam numinstances spam numinstances def printnuminstances(self)print("number of instances created%sspam numinstancesc:\codec:\python \python from spam import spam abc spam()spam()spam( printnuminstances(number of instances created spam printnuminstances(anumber of instances created spam(printnuminstances(number of instances created but fetching counter changes counterunfortunatelyas mentioned earliersuch an approach is completely unworkable if we don' have an instance availableand making an instance changes the class dataas illustrated in the last line here better solution would be to somehow mark method inside class as never requiring an instance the next section shows how using static and class methods todaythere is another option for coding simple functions associated with class that may be called through either the class or its instances as of python we can code advanced class topics