for loop code block
for-loop, python
Solution
Python runs everything on indentation. The indentation level is how it knows what goes with what.
For example, this works:
for i in range(10):
print i
But this blows up with an `IndentationError`:
for i in range(10):
print i
From docs:
Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.
Problem
I was reading the tutorial about python here and was wondering that if the for loop does not have a block like this {}, how would we know which block of code is in the for loop. Are we going to have to read it base on the indentation of the code? Or did I miss something fundamental about python? And while I was trying out some python code in notepad++ when I was in the for loop and create a new line in the middle of my code it for some reason made the line of code and everything above it a block of code while everything else below something different. Again am I missing something? I hope it's not bad programming practice.