and contexts of useyou may find this feature to be more useful in your own code than some programmers realize name mangling overview here' how name mangling workswithin class statement onlyany names that start with two underscores but don' end with two underscores are automatically expanded to include the name of the enclosing class at their front for instancea name like __x within class named spam is changed to _spam__x automaticallythe original name is prefixed with single underscore and the enclosing class' name because the modified name contains the name of the enclosing classit' generally uniqueit won' clash with similar names created by other classes in hierarchy name mangling happens only for names that appear inside class statement' codeand then only for names that begin with two leading underscores it works for every name preceded with double underscoresthough--both class attributes (including method namesand instance attribute names assigned to self for examplein class named spama method named __meth is mangled to _spam__methand an instance attribute reference self __x is transformed to self _spam__x despite the manglingas long as the class uses the double underscore version everywhere it refers to the nameall its references will still work because more than one class may add attributes to an instancethoughthis mangling helps avoid clashes--but we need to move on to an example to see how why use pseudoprivate attributesone of the main issues that the pseudoprivate attribute feature is meant to alleviate has to do with the way instance attributes are stored in pythonall instance attributes wind up in the single instance object at the bottom of the class treeand are shared by all class-level method functions the instance is passed into this is different from the +modelwhere each class gets its own space for data members it defines within class' method in pythonwhenever method assigns to self attribute ( self attr value)it changes or creates an attribute in the instance (recall that inheritance searches happen only on referencenot on assignmentbecause this is true even if multiple classes in hierarchy assign to the same attributecollisions are possible for examplesuppose that when programmer codes classit is assumed that the class owns the attribute name in the instance in this class' methodsthe name is setand later fetchedclass def meth (self)self def meth (self)print(self xi assume is mine pseudoprivate class attributes