December 2017
Beginner to intermediate
410 pages
12h 45m
English
The Python range function allows the user to create a sequence of values by providing a starting value, an ending value, and if needed, a step value. It is very similar to the slicing syntax in Appendix L. By default, if we give range a single number, this function will create a sequence of values starting from 0.
# create a range of 5 r = range(5)
However, the range function doesn’t just return a list of numbers. In Python 3, it actually returns a generator. (In Python 2, this is the behavior of the xrange function.)
print(r)
print(type(r))
If we wanted an actual list of the range, we can convert the generator to a list.
lr = list(range(5))
print(lr)
Before you decide to convert ...