Underscore Naming
Single Leading Underscore:
-
_var
-
Indicating a name is protected, for internal use. Not enforced by python interpreter
Double Leading Underscore:
__var
- Indicating a name is private. Enforced by interpreter, attempt to call it will trigger
AttributeError
Double Leading Trailing Underscore:
__var__
- Special methods (magic methods) defined by python language, avoid naming your own attribute
Single Trailing Underscore:
var_
- Avoid naming conflict with python keywords
Single Underscore:
_
- Temporary variable name, variables that are never used
- Example:
a, b, c, d = ([] for _ in range(4))
for _ in random_list:
some_operation()
Reference
Dan Bader - The Meaning of Underscores in Python
Tutorials Teacher - Python - Public, Protected, Private Members