DEV Community

Discussion on: Dead Simple Python: Iteration Power Tools

Collapse
 
ardunster profile image
Anna R Dunster

I find it fairly easy to intuit how range works, because mostly I've used it for range(len(something)) (alternatively range(1,len(something))) in which case it grabs every index of something. Like, if len(something) == 10, then the last item in something has an index of 9, so it makes sense that range wouldn't want to try to grab an index 10.

Sometimes this throws me off trying to use actual numbers in range(), though XD

For some reason I often have trouble confusing the syntax of slices and ranges, though. Less as I practice more, but it's not uncommon for my first entry of a statement to have : where it should have ,, or vice versa. Oops.

(Also, stepping by -1 is fun ;) )