Is there any official rule/proposal on how should the Python code be indented?
Note: Python uses 4 spaces as indentation by default. However, the number of spaces is up to you, but a minimum of 1 space has to be used.
It is easier to visually identify long nested code blocks with 4 spaces. Saves time when debugging. Agreed. For a language like C I'd rather use two, actually, but in C the visual clue provided by indentation is less important than it is in Python.
Python doesn't mind whether you use two spaces or four spaces (or any other number of spaces) as long as you are consistent. For example if you start off using four spaces for an indent, then you should always use four spaces.
The indent size - is how many whitespaces will be put in the indented line start. Sometimes it is done with tabs, sometimes with spaces, depending on configuration.
From PEP 8 (Python's official style guide):
Use 4 spaces per indentation level.
4 spaces, or hitting the tab button once. However, try to avoid the tab button. Sometimes it will give you indentation errors even when you indent correctly.
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