The range() function in Python generates a sequence of numbers. For example, range(6) generates the numbers from 0 to 5. We can write a small piece of code in Python and verify that:
for i in range(6): print(i)
The program will output:
0 1 2 3 4 5
Similarly, if we write range(1, 6), then the range() function will generate the numbers between 1 and 5, both inclusive.
for i in range(1, 6): print(i)
The above program will output:
1 2 3 4 5
In Python, we use the range() function in many ways. For example, if we want to iterate over numbers of a certain range in a …






0 Comments