Learning Python – Coding Style

  • Use 4-space inden­ta­tion, no tabs


  • Wrap lines so that they don’t exceed 79 char­ac­ters


  • Use blank lines to sep­a­rate func­tions and class­es, and larg­er blocks of code inside func­tions


  • When pos­si­ble, put com­ments on a line of their own


  • Use doc­strings


  • Use spaces around oper­a­tors and after com­mas


  • Name your class­es and func­tions con­sis­tent­ly; the con­ven­tion is to use Camel­Case for class­es and lower_case_with_underscores for func­tions and meth­ods


  • Always use self as the name for the first method argu­ment


  • Don’t use fan­cy encod­ings if your code is meant to be used in inter­na­tion­al envi­ron­ments

    Nam­ing con­ven­tions:

    Vari­ables / func­tions — use_lower_case_separated_by_underscore

    Class names — Use­Camel­Case

    Error class­es end in Error, i.e. MyEr­ror