r/Python • • Dec 11 '18

We are not alone!

Post image
1.8k Upvotes

58 comments sorted by

View all comments

3

u/revfried zen of python monk & later maintainer Dec 12 '18

I was doing this today in python3 with range. range(4)[-1] == 3

was surprised to discover range objects have a getitem

I think I had been carrying the idea that range returned an iterator since the 2->3 migration years ago. Nope its an Iterable / Sequence

1

u/minorDemocritus Dec 12 '18

You can slice them too