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 trialSahil Kapoor
8,932 PointsWhen does the scope of if gets end ?
for example age = 10 if age <15 : print("Hey Im less than 15 ") else print("hey im not less than 15") //now it i want to write any other statement like add a for loop how can i find out that its not a part of the else statement since python doesnt have braces "{}" like C or C++ in which the braces tells us that the statement is executed within the braces do reply thanks
1 Answer
Stuart Wright
41,120 PointsPython uses whitespace where other languages use {} - the level of indentation is important. For example:
if x > 10:
print("x is greater than 10."
else:
print("x is not greater than 10.")
print("This line is still indented so is part of the else block.")
print("This line is not indented so it will always be executed.")