Like zebra crossing in Italy, Python underscores are artistic embellishments?Sure, you can break the convention. But that's not the Python Way.
Tim Toady Bicarbonate says:Sure, you can break the convention. But that's not the Python Way.
double underscore is fine by me.There is some "best practice" usage in python.
Python's convention to make an instance variable "private" is to add a prefix "double underscore" __ (a _ for protected).
Python performs name mangling of private variables. Every member with double underscore will be changed to _object._class__variable.
If so required, it can still be accessed from outside the class, but the practice should be refrained.
Each sect has its own high priests. C++ is for consenting adults.Tim Toady Bicarbonate says:Sure, you can break the convention. But that's not the Python Way.
![]()
Indeed, people who used Perl should unlearn certain things in order to be happy coding in Python.Tim Toady Bicarbonate says:Sure, you can break the convention. But that's not the Python Way.
![]()
We don't have any choice in the matter.https://www.python.org/dev/peps/pep-0020/
"There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch."
sum_x = 0
for x in xs:
sum_x += x
sum_x = sum(xs)