Tabs versus spaces in Python programming


I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.

How does that make a difference? Are there other reasons why one would use spaces instead of tabs for Python? Or is it simply not true?

Should I switch my editor to insert spaces instead of tabs right away or keep on going like I used to?

1/26/2015 3:28:12 AM

Accepted Answer

Because PEP-8 tells us to use spaces.

8/18/2017 12:13:42 PM

Tired of chasing after indentation typos ( 8 spaces ? no, 7 oops 9 ... ) I switched my sources to 'tabs only'.

1 tab == 1 indent level, full stop

The point is: if you want to display the indentation as 4, 8 or pi / 12 character width, just change the settings in your text editor, don't mess with the code.

(Personally, I use 4 char width tab... but some would prefer 3 or 8 space, or even use variable width fonts.)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow