Name mangling
You'll notice that some of the variable names have leading double underscores. This is to define them as specifically related to this class. This is referred to as name mangling in Python.
In Python, a single, leading underscore creates a so-called private attribute or method, designed to keep the attribute from being directly accessed. It's not really private, as it can be called explicitly, but it won't be automatically imported when using the import statement.
Name mangling causes the attribute with double underscores to become _ClassName__attribute internally within Python. That is, the class name the attribute is associated with becomes part of the fully qualified name for the attribute.
Name mangling is intended to provide ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access