Passing a range into a function: Can't understand it!


#1



range(6) # => [0,1,2,3,4,5]
range(1,6) # => [1,2,3,4,5]
range(1,6,3) # => [1,4]


The range function has three different versions:

range(stop)range(start, stop)range(start, stop, step)

Why calling range(1,6,3) will give [1,4] in return? Can anyone please elaborate it!
Thanks in advance! :slight_smile:


#2

Start with 1. Now step 3. That gives 4. Step 3 again and we exceed the stop limit of 6. Thus, the output will be, [1, 4].


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.