Jul-31-2019, 01:13 PM
Think of the indexes as being between the items, rather than on the items:
BTW, Guido didn't come up with the idea. It's been around since the sixties, at least in computer science. There's more about the reasoning at Wikipedia.
Output:lunch = ['Spam', 'spam', 'spam', 'eggs', 'spam']
^ ^ ^ ^ ^ ^
| | | | | |
0 1 2 3 4 5
-5 -4 -3 -2 -1
If you just give one index, you get the item after it. That's why -1 gets you the last item. But if you give two indexes, you get everything between them. That's why 1:-1 gets you everything but the first and last item.BTW, Guido didn't come up with the idea. It's been around since the sixties, at least in computer science. There's more about the reasoning at Wikipedia.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures