The Range () function creates a list of variables for you to use, very common when working with “for” loops.

There are two ways to create a range:

  • Range (stop): this range starts with zero and ends with the number given as the stop value.
  • Range ([start], stop [step]): you give the function the lower bound, the upper bound and the difference between each value.

In case of ranges, all parameters must be integers, values can be positive or negative and the upper bound in both types is non-inclusive.

There were two types of ranges in python 2, range and x-range, now in python 3 we only have the range we all know and love.

It is also possible to create a random rage of numbers using the rand-range function, but since you have to import a module to use it you should just focus your attention in the first two.

In the python 3 range, ranges have their own data type, and before in python 2, ranges produced lists and x-ranges produced iterators minus a sequence.

CC BY 4.0 Creation and use of ranges by juansalvadorfernandez is licensed under a Creative Commons Attribution 4.0 International License.