When Does Whitespace Matter in Python?

When Does Whitespace Matter in Python?

The whitespace needs to be consistent. So if you start using 4 spaces, you have to consistently use 4 spaces for the entire block. If you use a tab, you now have to use a tab. Everywhere else, whitespace is not significant and can be used as you like, just like in any other language.

Does whitespace matter Python?

Whitespace Within Lines Does Not Matter

Most Python style guides recommend using a single space around binary operators, and no space around unary operators.

Why does whitespace matter in Python?

Python uses white space for two things: newlines terminate logical lines, and changes in indentation delimit blocks. ... If the space is less, that signifies the end of possibly multiple blocks. Only the space at the beginning of a logical line matters; continued physical lines can't start or end a block.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.