Python Conventions

General formatting and coding

  • Python uses spaces, in fact use 4-space indentation, and no tabs.
  • Wrap lines so that they don’t exceed 79 characters.
  • Use blank lines to separate functions and classes, and larger blocks of code inside functions.
  • Generally: use PascaleCase for class names and snake_case for functions and method defs. Always use self as the name for the first argument of class methods.
  • Use docstrings.
  • Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).
Last modified: August 22, 2022
© 2024