Python range() return value
Python range() returns an object of class type range.
Let us create a range object, store it in a variable, say my_range, and print the type of this variable.
Let us have a brief look of the range class definition.
- range class has three readonly properties: start, stop, and step.
- range class can be initialised with (stop), (start, stop), or (start, stop, step).
- range class has two methods: count(), and index().
Also, this range class object has an iterator that returns integers, using which we can iterate over the values. We can use For loop to iterate over the values in the given range.
For example, consider the following program. We have used a For loop to iterate over the
In this tutorial of Python Ranges, we learned what type of value does range() function return, and the different properties and objects this range class object has.