Table Of Contents

Previous topic

Introduction

Next topic

Python coding rules

General rules

The general rules apply to Python and C++ code.

Code lay-out

  • Use 4 spaces per indentation level.

  • Do not use tabs.

  • Do not exceed a line length of 80 characters (a few more characters are acceptable in exceptional cases).

  • Put a blank line at the end of each file (this is required by some compilers).

  • Align successive similar lines on common elements. Here an example illustrating the alignment on the = symbol:

    max     = par.max
    prompt  = par.prompt
    sum    += par.sum
    
  • Each function or method must terminate with a single return statement that is placed at the end of the function or method.

  • Always use English words (class names, method and function names, comments, documentation, etc.).