April 2019
Intermediate to advanced
646 pages
16h 48m
English
For private methods and functions, we usually use a single leading underscore. This is only a naming convention and has no syntactical meaning. But it doesn't mean that leading underscores have no syntactical meaning at all. When a method has two leading underscores, it is renamed on the fly by the interpreter to prevent a name collision with a method from any subclass. This feature of Python is called name mangling.
So some people tend to use a double leading underscore for their private attributes to avoid name collision in the subclasses, for example:
class Base(object): def __secret(self): print("don't tell") def public(self): self.__secret()class Derived(Base): def __secret(self): print("never ever")
From this ...