31. いつもの文句のタネ1
• 以下のような余計なスペースを使わない
- カッコの内側
- カンマ、セミコロン、コロンの手前
- 丸カッコや角カッコの手前
# OK
spam(ham[1], {eggs: 2})
# NG
spam( ham[ 1 ], { eggs: 2 } )
# OK
if x == 4: print x, y; x, y = y, x
# NG
if x == 4 : print x , y ; x , y = y , x
# OK
dict[‘key’] = spam(list[index])
# NG
dict [‘key’] = spam (list [index])
34. その他の推奨1
• 以下の2項演算子の左右には必ずスペース
代入 (=)・複合代入 (+=, -= etc.)
比較 (==, <, >, !=, <>, <=, >=, in, not in, is, is not)
論理 (and, or, not)
# OK
a = i + 1
b = x*2 - y*y
c = (a+b) * (a-b)
!
# NG
a = i+1
b = x * 2 - y * y
c = (a + b) * (a - b)