# This code will print the numbers 0-9 to the screen for i in range(10): print(i)
0
1
2
3
4
5
6
7
8
9
In this code, the for
loop is used to iterate over a sequence of numbers in the range
object. The range
object represents a sequence of numbers, in this case from 0 to 9. The for
loop will execute the indented code block once for each number in the range
object. In this case, the code block contains a single line that prints the current number to the screen.
The for
loop in Python allows you to iterate over a sequence of values, such as a list or range of numbers, and execute a block of code for each value in the sequence. This is a convenient way to perform a repetitive task without having to write the same code over and over again.
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.
Subscribe to be the first to know when a new Python course is released.