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

后端 未结 6 1864
天涯浪人
天涯浪人 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:35

    I wouldn't use very_long_variable_name as a default argument. So consider this:

    func(1, 2, axis='x', angle=90, size=450, name='foo bar')
    

    over this:

    func(1, 2, axis = 'x', angle = 90, size = 450, name = 'foo bar')
    

    Also, it doesn't make much sense to use variables as default values. Perhaps some constant variables (which aren't really constants) and in that case I would use names that are all caps, descriptive yet short as possible. So no another_very_...

提交回复
热议问题