Range question

Below is the range lesson URL.

I have a question regarding range. is a range a list? When I print out range(5), it prints out ‘range(5)’. But I still use ‘for loops’ with range as if it is a list. Also in order to make a range into a list I still have to use a method ‘list()’.
To say it again, I use range as if it is a list, and the lesson also says so, “zero_thru_one = range(2) # zero_thru_one is now [0, 1]”. However, when I print(zero_thru_one is now), the console shows range(2). Can someone clarify this for me?

https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-python-loops/lessons/learn-python-loops/exercises/range
You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

The detailed explanation is here:

https://treyhunner.com/2018/02/python-range-is-not-an-iterator/

but it also involves iterators and generators, not sure those have been covered yet. So it might be a tough read, but would give you good understanding.

2 Likes

thanks a lot. I appreciate it