gpt4 book ai didi

python - 不符合 PEP8 的代码 (E211) 是否会产生不良后果?

转载 作者:太空宇宙 更新时间:2023-11-03 14:23:26 25 4
gpt4 key购买 nike

假设有一个函数定义为:

def thingy(arg1):
pass

根据书籍和 PEP8 ( error code E211 ),我知道正确的调用方式是:

thingy(true)

但是,我在现有代码中也看到了如下形式:

thingy (true)

除了反对 PEP8,它是否有害?

特别是,它是否会产生使用推荐方式不会抛出的不需要的错误/副作用?

最佳答案

不,当在可调用对象和调用括号之间使用时,空格并不重要。

来自lexical analysis reference documentation :

Except at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separate tokens. Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens).

Besides NEWLINE, INDENT and DEDENT, the following categories of tokens exist: identifiers, keywords, literals, operators, and delimiters. Whitespace characters (other than line terminators, discussed earlier) are not tokens, but serve to delimit tokens. Where ambiguity exists, a token comprises the longest possible string that forms a legal token, when read from left to right.

强调我的。

在不需要空格的地方,它除了在视觉上分隔标记外没有任何意义。 thingy( 已经是两个独立的标记,当没有空格时不会被混淆为 one 标记。所以这里出现空格不会改变该行的解释。

关于python - 不符合 PEP8 的代码 (E211) 是否会产生不良后果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24208521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com