Naming styles

The different naming styles used in Python are:

  • CamelCase
  • mixedCase
  • UPPERCASE, and UPPER_CASE_WITH_UNDERSCORES
  • lowercase and lower_case_with_underscores
  • _leading and trailing_ underscores, and sometimes __doubled__ underscores

Lowercase and uppercase elements are often a single word, and sometimes a few words concatenated. With underscores, they are usually abbreviated phrases. Using a single word is better. The leading and trailing underscores are used to mark the privacy and special elements.

These styles are applied to:

  • Variables
  • Functions and methods
  • Properties
  • Classes
  • Modules
  • Packages

Variables

There are two kinds of variables in Python:

  • Constants
  • Public and private variables

Constants

For constant global variables, an uppercase with an underscore ...

Get Expert Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.