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

tab

when and in which situation should i tab (or make a space in my code)

1 Answer

Steven Parker
Steven Parker
243,656 Points

In Python, indentation is required for indicating what block of code a statement belongs to. So for examples, statements that are part of a conditional ("if"), or a loop ("for"), or a function ("def") will be indented to create a block under any of those.

Python will allow indentation using spaces or tabs, but not both within the same file. Also, the amount of indentation (2 spaces vs. 3 spaces, for example) is flexible, but must be consistent throughout a file.

You will see plenty of examples of indentation in the course videos.