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 Python Basics Functions and Looping Functions

1 Answer

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Faisal,

Good question! If you go into Workspaces and you have a file open, you will see a section below the file editing window which tells you which line and column you're at, and how many total lines your file has. If you look to the right of that section, you should see something telling you which language your file is written in (will say "Python" if it's a .py file), and then it will say either "Tab Size" or "Spaces", and then a number.

Let's say it says "Spaces 4" (this is a good setting for Python). In this case, when you hit the tab key on your computer, it will convert that "tab" into 4 spaces, which saves you from having to hit the space key 4 times. Notice that if you then use either the left arrow key, or the backspace, you will go back only one space, not the whole tab.

But if you click on "Spaces" and change it to "Tab Size" so that it now reads "Tab Size 4", try it again: starting from the left margin, hit tab, and you will get a tab that is the same size as 4 spaces. But if you hit the left arrow key or backspace, it will take you all the way back to the left margin; it didn't convert that tab into spaces.

For some programming languages that aren't especially sensitive to spaces (like JavaScript or HTML), it's not really an issue, so you can use whatever you feel like using, without breaking the program.

But Python is really sensitive to indentation, so if you have mixed tabs and spaces, even though it looks the same to you on the page, Python thinks they are different. i.e., as far as Python is concerned, a single tab that happens to be 4 spaces wide is not the same thing as 4 actual spaces, which is also not the same as two tabs that are each two spaces wide... even though they all look the same on the page!

So for Python, it is usually best to use the "Spaces" setting on Workspaces (and any other editor you may be using locally for testing your scripts). That way, you can be sure that they not only look to be indented the same, but they are indented the same.

I hope this helps!