Range() I dont understand


#1

Hei. I see that many times we have to add range in our code. What is range, and what does it do?


#2

Hmm you could think of it like a for-loop, which iterates through the given numbers and adds those to a list, like:

range(4) will actually be a list -> [0,1,2,3]

but you can also take a specific part of numbers:

range(5,10) -> [5,6,7,8,9]

so if you use this in a for loop for example:

for x in range(3,7):
print x

the output will be:

3
4
5
6