4 ms·
Only names which start with double underscores AND do not end with double underscores.
by rnice 1y ago
Only names which start with double underscores AND do not end with double underscores.
- mdaniel 1y agoDoesn't the "__hello" def qualify for your description? It shows up in both dir() outputs, although admittedly it is "name mangled" with the outer class name, so maybe that's what they meant I guess this could qualify for a TIL because I didn't know Python treated leading and trailing dunders any different and that they were its implementation of "protected" and "private" only by convention
- arjvik 1y agoThe name mangling is what is being referred to. Specifically, you can access it as Sekrit()._Sekrit__hello(), but that's a pretty obvious boundary-break compared to .__hello(). Members ending in a double underscore as well aren't mangled, because this interferes with syntax sugar methods like __add__ (addition operator overloading).