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 trialsarwesh gajbhiye
387 Pointswhy we put indentation before print()
why we left space before print() . whats the reason and logic
3 Answers
Thananjaya Chakravarthy
4,672 Pointscan 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".
Henry Hornung
1,028 PointsLines 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
4,672 Pointsyou have to tell to the editor or interpreter, whatever you call. That particular print statement belongs to 'if','for'...
sarwesh gajbhiye
387 Pointssarwesh gajbhiye
387 Pointsyeah but why indentation is required under "if" , "for" .