Python教程指出:"在运算符周围和逗号后使用空格,但不要直接在括号结构内部使用:a = f(1, 2) + g(3, 4)。" 那么 "不要直接在括号结构内部使用" 空格具体指什么呢?
Python教程指出:"在运算符周围和逗号后使用空格,但不要直接在括号结构内部使用:a = f(1, 2) + g(3, 4)。" 那么 "不要直接在括号结构内部使用" 空格具体指什么呢?
这可能来自于PEP 8 -- Python代码风格指南。具体来说,请参阅“表达式和语句中的空格”一节。
从该部分可以得到以下信息:
Avoid extraneous whitespace in the following situations:
- Immediately inside parentheses, brackets or braces.
Yes: spam(ham[1], {eggs: 2})
No: spam( ham[ 1 ], { eggs: 2 } )
x = (1, 2)
不是这个:
x = ( 1, 2 )
a = f(1)
或者l = [2, 3]
。