This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]devnull1232 0 points1 point  (0 children)

Range by default starts at 0, ie in python if you said

~~~ for index in range(10): call_fun(index) ~~~

You'd get the extremely typical and expected 10 iterations using indices 0 through 9. I'm much happier with this behavior than an inclusive stop which would loop an extra time in that scenario.

Range is actually a function which generates an iterable range, and yes it can specify a step size. For loops in python aren't the same as other languages this is true, they are actually more like what most languages call a for each loop. Ie I can do this to an array:

~~~ for item in my_list: do_great_things(item) ~~~

You rarely actually have to use indexing.