DEV Community

Discussion on: Python/Django Developer Interview Questions and Answer (#1)

Collapse
 
manishanaidu profile image
Manisha Naidu • Edited

There is no concept of private variables in Python. So "__" is just the convention followed to achieve similar concept.

Collapse
 
lhaze profile image
Łukasz Haze

"Name mangling" (so called) was't meant to be confused with the concept of "privacy". It's a common misconception. It's in the language to help to mitigate the problem of class field name collisions while the inheritance comes into the game. Think of the __slots__ class attribute or any API-like class mechanics using both inheritance and class fields (Django models). You may want to have each subclass add its value to the mechanics, not to override superclasses' values.

Collapse
 
chayimfriedman2 profile image
Chayim Friedman

Wait. Isn't it exactly what I said?

And besides, many developers (including me) prefers a single underscore, even though it has no meaning for Python.