简体   繁体   English

Python编码风格的空格

[英]Spaces in Python coding style

Python tutorial says "Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4)." Python教程说:“在运算符周围和逗号后使用空格,但不能直接在括号结构中使用:a = f(1,2)+ g(3,4)”。 What does "not directly inside bracketing constructs" exactly mean? “不直接在包围结构内”是什么意思?

That probably comes from PEP 8 -- Style Guide for Python Code . 这可能来自PEP 8-Python代码样式指南 Specifically, see the section on "Whitespace in Expressions and Statements." 具体来说,请参见“表达式和语句中的空白”部分。

From that section: 从该部分:

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

这意味着你不应该做a = f ( 1 )l = [ 2, 3 ]a = f ( 1 )事情。

I think it means do this: 我认为这意味着这样做:

x = (1, 2)

not this: 不是这个:

x = ( 1, 2 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM