April 2017
Beginner to intermediate
312 pages
7h 23m
English
In Python, it is possible to implement a loop within a loop. For example, let's say we have to print x and y coordinates of a map. We can use nested loops to implement this:
for x in range(0,3): for y in range(0,3): print(x,y)
The expected output is:
Be careful about code indentation in nested loops as it may throw errors. Consider the following example:for x in range(0,10): for y in range(0,10): print(x,y)
The Python interpreter would throw the following error:
SyntaxError: expected an indented block
This is visible in the following screenshot:
Hence, it is important to pay attention to indentation in Python (especially ...
Read now
Unlock full access