PEP 8, why no spaces around '=' in keyword argument or a default parameter value?

后端 未结 6 1762
天涯浪人
天涯浪人 2021-01-30 09:54

Why does PEP 8 recommend not having spaces around = in a keyword argument or a default parameter value?

Is this inconsistent with recommending spaces around every other

6条回答
  •  面向向阳花
    2021-01-30 10:32

    I think there are several reasons for this, although I might just be rationalizing:

    1. It saves space, allowing more function definitions and calls to fit on one line and saving more space for the argument names themselves.
    2. By joining each keyword and value, you can more easily separate the different arguments by the space after the comma. This means you can quickly eyeball how many arguments you've supplied.
    3. The syntax is then distinct from variable assignments, which may have the same name.
    4. Additionally, the syntax is (even more) distinct from equality checks a == b which can also be valid expressions inside a call.

提交回复
热议问题