Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python range() function is used to return a sequence. By default, sequence starts from 0 and ends at specified integer with increment of 1. Range() function has two optional arguments, which can be used to define starting point and increment / decrement factor of the sequence.

Syntax

range(start, stop, step_size)

Parameters

start Optional. An integer. starting point of sequence. default is 0.
stop Required. An integer. end point of sequence.
step_size Optional. An integer. step size of sequence. default is 1.

Example:

The below example describes how to use range() function to return a sequence.

MyRange = range(4)
for i in MyRange:
  print(i)

MyRange = range(10, 14)
for i in MyRange:
  print(i)

MyRange = range(-2, -10, -2)
for i in MyRange:
  print(i)

The output of the above code will be:

0
1
2
3

10
11
12
13

-2
-4
-6
-8

❮ Python Built-in Functions