Python range - Create the arithmetic progression in Python

In Python, range makes an arithmetic sequence similar to a list.

a = range(4)

for i in a:
    print(i)

# 0
# 1
# 2
# 3

You can get the each item in for loop. Let's check another example.

a = range(7)

for i in a:
    print(i)

# 0
# 1
# 2
# 3
# 4
# 5
# 6

Python range is not a list

Python range looks like a list but, to be exact, is not a list.

a = range(7)

print(a)
# range(0, 7)

print(type(a))
# <class 'range'>

type function returns the type of object. You can see the type of range is range, not list. But range object can be iterated in loop like list.

Python List

Python Tutorial