Référence de 2013 : page 257
Lire les explications actuelles : Écrire du code lisible, documenté et testé.

Texte intégral sélectionnable
La transcription conserve le texte extrait. Pour l’indentation d’un exemple ou une illustration, consulte la reproduction au-dessus ou le PDF original.
# Oui
spam(ham[1], {eggs: 2})
# Non
spam( ham[ 1 ], { eggs: 2 } )
Juste avant une virgule, un point-virgule ou un signe deux points :
Code : Python
# Oui
if x == 4: print x, y; x, y = y, x
# Non
if x == 4 : print x , y ; x , y = y , x
Juste avant la parenthèse ouvrante qui introduit la liste des paramètres d'une fonction :
Code : Python
# Oui
spam(1)
# Non
spam (1)
Juste avant le crochet ouvrant indiquant une indexation ou sélection :
Code : Python
# Oui
dict['key'] = list[index]
# Non
dict ['key'] = list [index]
Plus d'un espace autour de l'opérateur d'affectation = (ou autre) pour l'aligner avec une autre instruction :
Code : Python
# Oui
x = 1
y = 2
long_variable = 3
# Non
x = 1
y = 2
long_variable = 3
Toujours entourer les opérateurs suivants d'un espace (un avant le symbole, un après) :
affectation : =, +=, -=, etc. ;
comparaison : <, >, <=, …, in, not in, is, is not ;
booléens : and, or, not ;
arithmétiques : +, -, *, etc.
Code : Python
# Oui
i = i + 1
submitted += 1
x = x * 2 - 1
hypot2 = x * x + y * y
Partie 5 : Annexes
257/267
www.openclassrooms.com