Python name mangling transforms names that begin with two underscores and do not end with two underscores. It helps reduce accidental access and keeps similarly named private attributes distinct across classes. section 15.9 section 15.11
The practical rules are:
- A name such as `__y` in class `Mine` is stored as `_Mine__y`; methods with matching names are mangled too. section 15.9
- The original spelling `m.__y` does not access the attribute, but a method in `Mine` can use `self.__y`. Mangling is not enforced privacy: the transformed name can be used deliberately. section 15.9
A private instance variable
With `self.__y = 3` in `Mine`, `m.__y` raises `AttributeError`, while `m.print_y()` can print the value. The stored attribute is named `_Mine__y`. section 15.9
dir(m) ['_Mine__y', ... 'print_y', 'x']
Inspect the instance’s attributes to see the mangled name `_Mine__y`. section 15.9


