Python – What does range() function return

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.

my_range = range(4, 9)
print(type(my_range))
Run Code

Let us have a brief look of the range class definition.

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

my_range = range(4, 9)
for i in my_range:
    print(i)
Run Code

Summary

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.

Related Tutorials

Privacy Policy Terms of Use

SitemapContact Us