# 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.
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.