classes and object-oriented programming class ( )def _init_ (self) _init_ (selfself _x def _spam(self)pass mangled to self _b_ _x mangled to _b_ _spam(although this scheme provides the illusion of data hidingthere' no strict mechanism in place to actually prevent access to the "privateattributes of class in particularif the name of the class and corresponding private attribute are knownthey can be accessed using the mangled name class can make these attributes less visible by redefining the _dir_ (methodwhich supplies the list of names returned by the dir(function that' used to inspect objects although this name mangling might look like an extra processing stepthe mangling process actually only occurs once at the time class is defined it does not occur during execution of the methodsnor does it add extra overhead to program execution alsobe aware that name mangling does not occur in functions such as getattr()hasattr()setattr()or delattr(where the attribute name is specified as string for these functionsyou need to explicitly use the mangled name such as _classname_ _name to access the attribute it is recommended that private attributes be used when defining mutable attributes via properties by doing soyou will encourage users to use the property name rather than accessing the underlying instance data directly (which is probably not what you intended if you wrapped it with property to begin withan example of this appeared in the previous section giving method private name is technique that superclass can use to prevent derived class from redefining and changing the implementation of method for examplethe bar(method in the example only calls _spam()regardless of the type of self or the presence of different _spam(method in derived class finallydon' confuse the naming of private class attributes with the naming of "privatedefinitions in module common mistake is to define class where single leading underscore is used on attribute names in an effort to hide their values ( _namein modulesthis naming convention prevents names from being exported by the from module import statement howeverin classesthis naming convention does not hide the attribute nor does it prevent name clashes that arise if someone inherits from the class and defines new attribute or method with the same name object memory management when class is definedthe resulting class is factory for creating new instances for exampleclass circle(object)def _init_ (self,radius)self radius radius create some circle instances circle( circle( lib fl ff