June 2017
Beginner
352 pages
8h 39m
English
Let's move on and look at range, which many developers wouldn't consider to be a collection, although we'll see that in Python 3 it most definitely is.
A range is a type of sequence used for representing an arithmetic progression of integers. Ranges are created by calls to the range() constructor, and there is no literal form. Most typically we supply only the stop value, as Python defaults to a starting value of zero:
>>> range(5)range(0, 5)
Ranges are sometimes used to create consecutive integers for use as loop counters:
>>> for i in range(5):... print(i)...01234
Note that the stop value supplied to range() is one past the end of the sequence, which is why the previous loop didn't print
Read now
Unlock full access