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

Python

Indentation in Python - best practices

Hello,

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,870 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