Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Indentation in Python - best practices


I'm getting a lot of errors related to indentation in Python.

I know, it's recommended to use spaces, instead of tabs, but what are other best practices? What if you have wrong code, how to fix indentation - any tool?

One indent should be 2 spaces?

Python 3 won't allow you to mix tabs and spaces for indentation. And 4 spaces is the recommended indentation level. This can be automatically applied on the bottom right hand corner just above the console space.

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,822 Points

Have you checked out the PEP8 Docs? Also, articles discussing PEP8 like Beautiful PEP8 Python Code.

Some IDEs like PyCharm have pep8 helpers - not sure about others but probably easy enough to find with a little searching.

:tropical_drink: :palm_tree:

Moderator Edit: Moved response to Answer section