+ 1
What is difference between ::: for i in range (). Or for i in ()
3 Answers
+ 5
range(3) does not create numbers [0,1,2,3], but [0,1,2], as the last number is not included!
Mandrine , To learn how range() is working you can have a look to the python docs by using a browser or you can use the console to type in:
help(range)
you will get syntax and some more information about this function and class.
+ 3
The for loop iterates over a sequence or an iterable object. In this case, range() is a function that returns a sequence of numbers. For example range(3) is similar to as [0,1,2] (as a range object), so for i in range(3) will iterate over [0,1,2]. This is similar to just writing for i in [0,1,2]. This isn't limited to numbers. For example, to iterate over some words, you can write for i in ("red", "blue", "green").
+ 1
Lothar Forgot about that. My bad. I'll edit it out.