Skip to main content
  1. Posts/

Range

·178 words·1 min

If you are wondering how to use range() function this blog will tell you everything.

Definition of Range() and Usage #

So what is range?

Basically range starts at a default 0 and step by 1 and stop at a specific number but not including itself

Correct way to use range:

range(start, stop, step)

Parameter Values #

Parameters Description
start start is 0 by default optional, you can choose what number to start with
stop stops at a specific number but not including itself
step How much the number is going up by stepping up by

More Examples on how to use it #

#Using for-loop and simple

for f in range(1, 4, 2):
    print(f)

Output:

1
3

#Using a variable for the range

i = range(11)

for t in i:
    print(t)

Output:

0
1
2
3
4
5
6
7
8
9
10

#If you want to print the index of num shown down below

num = [1, 2, 3, 4]

for n in range(len(num)):
    print(n)

Output:

0
1
2
3

This is the end of range()