Skip to main content
 首页 » 编程设计

python之Python编码风格中的空格

2025年05月04日10luoye11

Python 教程说“在运算符周围和逗号后使用空格,但不要直接在括号结构内:a = f(1, 2) + g(3, 4)。” “不直接在括号结构内”到底是什么意思?

请您参考如下方法:

这可能来自 PEP 8 -- Style Guide for Python Code .具体请参阅“表达式和语句中的空格”部分。

从那个部分:

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 } )