Gambiarra :)
These things were inserted into the language very late, as these identifiers might already be being used by existing Python codes needed to do something to not break existing codes and as the __
is "reserved" solved the issue.
These identifiers are for "magical" members of the language, so it’s not a common name, it’s something that the language treats in a special way and generates something specific.
The __init__
for example it is a method that will initialize the object, what you write there will be executed every time an object is instantiated. The language will call you.So it’s not just any method, its presence in your code tells the language what it should do.
The official explanation is that this is to differentiate that it is a "magic" function, but it is not consistent.
Related: "__" or "Dunder" methods in Python, which are the most used?
– Renan Gomes