r/PythonLearning • • 6d ago

i am stuck with the range function

sorry but i am gonna crash out because of the range function i cant understand it well to use it this is driving me crazy any one could give me a video explaining everything i dont mind it being an hour long

10 Upvotes

33 comments sorted by

View all comments

1

u/atarivcs 6d ago

The purpose of the range function is to create a sequence of integers. Usually you would then use this sequence in a for loop, but there are other uses too.

range() can take one, two, or three arguments.

If you pass one argument, the sequence starts at 0 and continues up to (but not including) the argument. So for example range(5) produces the sequence 0,1,2,3,4.

If you pass two arguments, the sequence starts at the first argument and continues up to (but not including) the second argument. So range(4,11) produces the sequence 4,5,6,7,8,9,10.

If you don't want the sequence to be consecutive, you can pass a third argument which is used as the "step" increment between values. range(1, 8, 2) produces the sequence 1,3,5,7.

What is the exact problem you have having?