Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Y B
14,136 PointsTabs vs spaces
I had thought from the PEP style guide that the suggested practice was to use spaces (x4) after colons rather than tabs. But in the 1st OOP video Kenneth mentions using tabs.
Can someone confirm what the best practice should be, or does it not matter?
Thanks,
5 Answers
Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 PointsHi well in my opinion you should use the spaces : the thing is that building code blocks you need 4 spaces.
If you look at any other language you do:
if ( x !==y )
{code block
some code
}codeblock
something else
The curly braces are the body of the block.
But in Python:
if ( x !==y )
code block
----some code
codeblock
something else
You can use the tab but be sure to set the tab to 4 spaces or else your code block will be void.
Thats the only thing it think.
Y B
14,136 Pointsthanks how do you set tab to 4 spaces?
Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 PointsWell it depends on which text editor you use. On notepad++ you can set in -> Preferences -> Tab Settings -> and then you can set for different types : for python is set to 4 (but you can also enable Replace by space).
So it depends.
Just check the documentation of your text editor.
Y B
14,136 PointsThanks
Kenneth Love
Treehouse Guest TeacherPython doesn't care so long as it's consistent throughout the file. PEP 8 does suggest using spaces but most editors will gladly insert spaces when you press the tab key. That's likely why I said "tab". But, again, it doesn't actually matter.