James's Ramblings

Python: Underscores

Created: September 02, 2020

Single Leading Underscore

  • A PEP8 convention to show that a variable or method is intended for internal use only.

Double Leading Underscore

  • The Python interpreter mangles names with double leading underscores to prevent collisions with subclasses.

Single Trailing Underscore

  • A PEP8 convention for the use of reserved keywords as variable or method names.

Double Trailing Underscore

  • Used for dunder methods.
  • Dunder methods are in-built methods such as __init__.