PEP-8 states:
You should use two spaces after a sentence-ending period.
In my usual refactoring, I am used to replacing such consecutive double spaces with a single one, thinking that this habit has come from the typewriter days (I have went through this Wikipedia page briefly).
Also most of the times I have seen mono-space fonts being used for the programming, so it's much clearer than the other cases which can sometimes need 2 spaces to easily identify sentences.
Is there any reason behind this being used in PEP-8?
The reason for spaces is that tabs are optional.
Tabs or Spaces? Spaces are the preferred indentation method. Tabs should be used solely to remain consistent with code that is already indented with tabs. Python disallows mixing tabs and spaces for indentation.
PEP 8 is a document that provides various guidelines to write the readable in Python. PEP 8 describes how the developer can write beautiful code. It was officially written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The main aim of PEP is to enhance the readability and consistency of code.
Only those who authored the PEP can answer the "why" with any degree of certainty.
I've had a look at the standard library source code, and my conclusion is that this particular aspect of the style guide is not followed consistently: some standard modules follow it and some don't.
Until you pointed it out, I've never heard of the double space convention, and have never noticed anyone following it.
The answer is simple: readability :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With