--Originally published at Sierra's Blog
I’ve used in others posts the range function but I have never explained it.
The range function is a python predeterminated function that creates a list and are principaly used in loops.
There are different ways of using the range functions, here are them:
1.- range(Number): this will create a list which starts in 0 and end up one number before the one you wrote, for example:
for i in range(7):
print(i)
will produce this outcome:
0
1
2
3
4
5
6
2.-range(First number, Last Number) this way you’re telling python that you don’t want to start in 0.
Note: Python doesn’t read the last number, it stops 1 number before, for example:
for i in range (7,10):
print(i)
will produce this outcome:
7
8
9
Three parameters: range(First Number, Last number, Number that is going to be added)
for example:
for i in range(0, 10, 2): #will produce:
0
2
4
6
8
#it won’t print 10 because it’s the last number.
This page explains a lot of stuffs about range function: http://pythoncentral.io/pythons-range-function-explained/
Thanks for watching;)