FMP AudioLabs
B

Python Style Guide

This notebook makes some general recommendations for coding conventions as often used in Python.

Our recommendation closely follows the PEP 8 Style Guide for Python Code. Note that such coding conventions are only rough guidelines, and specific projects may follow other conventions. Use the guidelines only if there are no reasons to do something else. In the following, we list a couple of general conventions:

Use ' instead of " for strings

In [1]:
x = 'string'  # good
x = "string"  # bad

Use spaces after commas

In [2]:
x = [1, 2, 3]  # good
x = [1,2,3]    # bad

Use no space before or after brackets

In [3]:
x = range(1, 10, 2)    # good
x = range( 1, 10, 2 )  # bad

Use under_score instead of CamelCase or mixedCase for variable names and function names.

In [4]:
my_variable = 1  # good
myVariable = 1   # bad

Use spaces around = in assignments of variables.

In [5]:
x = 1  # good
x=1    # bad

Don't use spaces around = in assignments of parameters.

In [6]:
x = dict(a=1)    # good
x = dict(a = 1)  # bad

Use spaces around operators like +, -, *, /, etc.

In [7]:
x = 1 + 2  # good
x = 1+2    # bad
Acknowledgment: This notebook was created by Frank Zalkow and Meinard Müller.
C0 C1 C2 C3 C4 C5 C6 C7 C8