Member-only story

Python: Range Function Tutorial

Jesse L
2 min readDec 9, 2021

--

Hi everyone, welcome back. Today, we will go over the range() function in Python and see how it works. The range() function is a common function that is capable of returning a sequence of numbers. Let’s get into it.

Range Function

Let’s see how the range function works:

for x in range(5):
print(x)
Output:
0
1
2
3
4

We created a for loop that will loop for each number within our range. By default the range will start at 0 and increment by 1. The 5 that was passed in with the range function, tells the function when to stop creating numbers and does not include the 5.

Range Function Parameters

The parameters of the range function are a starting range, a stopping range, and a stepper.

range(start, stop, stepper)

The starting range is an optional parameter which tells the range at which value to start. By default, it starts at 0.

The stopping range is a required parameter which tells the range at which value to stop and does not include that value.

The stepper is an optional parameter which tells the range how much to increment the value. By default, it starts at 1.

Range Function Start…

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet