3

Just wondering how to get the same functionality out of range() that you get in python 2.7 in version 3?

In python 2.7:

>>> range(5)
[0, 1, 2, 3, 4]

In python 3:

>>> range(5)
range(0, 5)

I need to get a list that looks like the one above, but am restricted to using python3 for an assignment...

Thanks so much!

1
  • 1
    It still kind of behaves like a list, so aside from the way it shows up in the REPL, is it causing any problems? Commented Jul 22, 2013 at 1:26

1 Answer 1

6

Simply do this:

list(range(5))
=> [0, 1, 2, 3, 4]

In Python 3, range() returns an iterable of objects, but it's easy to convert it to a list, as shown above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.