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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With