DEV Community

Zeeshan Asgar
Zeeshan Asgar

Posted on

Looping over a range of numbers in Python3

for i in range(7):
    print(i**3)
Enter fullscreen mode Exit fullscreen mode

We have used range here to generate the sequence of numbers.

range(stop)

returns the sequence of numbers up to stop argument.

range takes two other arguments as well

  1. start
  2. step

range(start, stop[, step])

start argument tells where to start the sequence from. Defaults to 0.
step argument tells the increment value between each number in the sequence. Defaults to 1.

Note - range in Python3 returns a range object, not list.

Top comments (0)