Python: Naming variables

  • _variable: A convention to indicate a variable or function is internal.
  • __variable: Within a class Python mangles the name as _ClassName__variable, useful in avoiding name clashes in sub-classes.
  • variable_: Can be used to avoid clash with keywords like class_.
  • __variable__: Known as “dunder” and are special methods of a class used to implement protocols.

Leave a comment