wxl24life wxl24life - 1 year ago 256
Python Question

Does PEP require whitespace around operators in function arguments?

I have this code:

some_list = range(a, b+1)

After checking my coding style with pep8 plugin for vim, I got this warning:

missing whitespace around operator

It seems that to be compliant with PEP 8 I should instead write this?

some_list = range(a, b + 1)

But I have read PEP 8 - Style Guide for Python Code several times and just can't find the rule applied to the warning above.

So I want to know: when using PEP-8 style, is whitespace needed around operators(+,-,*,/,etc) in a function's arguments?

Answer Source


Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).

The exception to that is when = is used to set named parameters.


I've looked through the source code of Python's standard library and found an occurrence of the scenario presented above:


            end = _w(s, end + 1).end()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download