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 (2015) Logic in Python Around and Around

sarwesh gajbhiye
sarwesh gajbhiye
387 Points

why we put indentation before print()

why we left space before print() . whats the reason and logic

3 Answers

Thananjaya Chakravarthy
Thananjaya Chakravarthy
4,672 Points

can yo be specific. There is no need to apply indentation before print statements. Indentation is required for print statements only if print statements comes under the "if",''for","while" and "define functions".

sarwesh gajbhiye
sarwesh gajbhiye
387 Points

yeah but why indentation is required under "if" , "for" .

Henry Hornung
Henry Hornung
1,028 Points

Lines of code that happen when something else happens are indented. under an if statement everything is indented 1 above the if statement header. once the whole if statement ends, the indentation for regular lines of code goes back that of the if statement header. (ex.) if (whatever you're testing): <--- if statement header (stuff that you'll do)<----- this is indented x += 56.34

^ indentation returns to the previous amount | because the if statement is over |

Thananjaya Chakravarthy
Thananjaya Chakravarthy
4,672 Points

you have to tell to the editor or interpreter, whatever you call. That particular print statement belongs to 'if','for'...