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

Michele Dashiell
Michele Dashiell
1,564 Points

My biggest problem with Python and the quizzes and really in general

So I think the biggest problem that I have with Python and the quizzes ( and really writing Python in general) are the indents. I am having trouble with deciding how much to indent certain things, like while and for loops and functions. Can anyone point me to somewhere that explains the python indent rules in detail? Thanks!

1 Answer

John Lindsey
John Lindsey
15,641 Points

Basically, whenever you use a colon, you will indent the following lines (which are a block) that go with the line with the colon. For an if statement, you would want to indent everything that comes after what you want to test. Ex:

if color == blue:
    print('The color is blue!')
print('This is no longer in the if statement because it is not indented')

That is just a simple example. I did a quick google search and this site came up for indents: http://www.diveintopython.net/getting_to_know_python/indenting_code.html

Hope this helps!