Skip to content

Instantly share code, notes, and snippets.

@gwsu2008
Created April 11, 2020 17:58
Show Gist options
  • Save gwsu2008/014648ec89960f7d1471715858a51419 to your computer and use it in GitHub Desktop.
Save gwsu2008/014648ec89960f7d1471715858a51419 to your computer and use it in GitHub Desktop.
python_underscore.py
1. Single Leading Underscore: _var
The underscore prefix is meant as a hint to another programmer that a variable or method starting with a single underscore is intended for internal use. This convention is defined in PEP 8.
2. Single Trailing Underscore: var_
In summary, a single trailing underscore (postfix) is used by convention to avoid naming conflicts with Python keywords. This convention is explained in PEP 8.
3. Double Leading Underscore: __var
A double underscore prefix causes the Python interpreter to rewrite the attribute name in order to avoid naming conflicts in subclasses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment