لَآ إِلَـٰهَ إِلَّا هُوَ
LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.

Lesson 19: The range() function in Python

The range() function in Python is an in-built function. It returns a sequence of numbers starting from zero and increment by 1 by default and stops before the given number.

Example Code 1: The range() function.


output will be
0
1
2
3
4
5
Note: be range(0,6) excluding 6.

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.

Syntax

range(start, stop, step)

Parameter Description

start-----> Optional. An integer number specifying at which position to start. Default is 0

stop-----> Required. An integer number specifying at which position to stop (not included).

step-----> Optional. An integer number specifying the incrementation. Default is 1.

Example Code 2: The range() function Create a sequence of numbers from 2 to 6, and print each item in the sequence.


output will be
2
3
4
5

Example Code 3: The range() function Create a sequence of numbers from 2 to 21, but increment by 2 instead of 1.


output will be
2
4
6
8
10
12
14
16
18
20