Starting value

We can also supply a starting value if we wish:

>>> range(5, 10)
range(5, 10)

Wrapping this in a call to the list() constructor is a handy way to force production of each item:

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

This so-called half-open range convention — with the stop value not being included in the sequence — at first seems strange, but it actually makes a lot of sense if you're dealing with consecutive ranges because the end specified by one range is the start of the next one:

>>> list(range(10, 15))
[10, 11, 12, 13, 14]
>>> list(range(5, 10)) + list(range(10, 15))
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset