Aug-02-2019, 08:32 PM
Say you have a slice from a to b (a:b). If you think of 0 being the index of the first item, 1 being the index of the second item, and so on, then a:b gets items with the indexes a, a + 1, a + 2, ..., b - 2, and b - 1. Note that b is not in that list. It is excluded, and it is the upper bound, so this is called upper bound exclusive.
I prefer to think of the indexes as being between the items, rather than on the items:
I prefer to think of the indexes as being between the items, rather than on the items:
Output:lunch = ['Spam', 'spam', 'spam', 'eggs', 'spam']
^ ^ ^ ^ ^ ^
| | | | | |
0 1 2 3 4 5
-5 -4 -3 -2 -1
So if a is 1 and b is 4, you get the three items between 1 and 4 in the above diagram.
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