Python range() function

Published February 16, 2022

The range() function in Python returns the sequence that corresponds to the given pair of numbers. This function enables the user to create an integer sequence inside a specified range.
Based on that number of parameters the user passes to the function, the user may choose where the sequence of integers begins and ends and how much difference there is between one number and the next.

Syntax

range(stop)

range(start, stop[, step])

where, range() accepts three parameters in total including:

Start: the number wherein the series of integers must be returned.
Stop: the number whereupon the series of integers must be returned.
Step: the integer number specifies the increase between every number in the series.


Example

for i in range(9):
    print(i, end=" ")
print()
for i in range(50):
    print(i, end=" ")


    
    
Output

0 1 2 3 4 5 6 7 8

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

328 Views