I read PEP 8: Style Guide for Python and I wasn’t quite sure how to style mathematical operators inside arguments.
For example, for the = sign PEP 8 says
Yes:
x = 3
y = foo(bar=3)
No:
x=3
y = foo(bar = 3)
But what about other mathematical operators like -, +, /, etc. Which is good style?
foo_bar = bar[i - 3][j + 2]
z = foobar(y=i - 1, z=k + 2)
or
foo_bar = bar[i-3][j+1]
z = foobar(y=i-1, z=k+2)
?
To be honest, the latter looks better in my opinion.
From PEP 8:
Other Recommendations
-
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).
-
Use spaces around arithmetic operators:
-
Don’t use spaces around the = sign when used to indicate a keyword argument or a default parameter value.
Right up at the top of Pep 8 is this advice:
There are two exceptions made explicit, and I think argument passing falls under this:
I’d leave out the spaces in the arguments, making your example: