1a[-1] # last item in the array
2a[-2:] # last two items in the array
3a[:-2] # everything except the last two items
4
1word = "Example"
2
3# Obtain the first 3 characters of "Example"
4# E x a m p l e
5# 0 1 2 3 4 5 6
6# First 3 characters = "Exa"
7sliced_word = word[:3] # Gives you "Exa"
8
9# Everything after character #3 = "mple"
10second_sliced_word = word[3:] # Gives you "mple"
1# array[start:stop:step]
2
3# start = include everything STARTING AT this idx (inclusive)
4# stop = include everything BEFORE this idx (exclusive)
5# step = (can be ommitted) difference between each idx in the sequence
6
7arr = ['a', 'b', 'c', 'd', 'e']
8
9arr[2:] => ['c', 'd', 'e']
10
11arr[:4] => ['a', 'b', 'c', 'd']
12
13arr[2:4] => ['c', 'd']
14
15arr[0:5:2] => ['a', 'c', 'e']
16
17arr[:] => makes copy of arr
1# array[start:stop:step]
2
3# start = include everything STARTING AT this idx (inclusive)
4# stop = include everything BEFORE this idx (exclusive)
5# step = (can be committed) difference between each idx in the sequence
6
7arr = ['a', 'b', 'c', 'd', 'e']
8
9arr[2:] => ['c', 'd', 'e']
10
11arr[:4] => ['a', 'b', 'c', 'd']
12
13arr[2:4] => ['c', 'd']
14
15arr[0:5:2] => ['a', 'c', 'e']
16
17arr[:] => makes copy of arr
1a[start:stop] # items start through stop-1
2a[start:] # items start through the rest of the array
3a[:stop] # items from the beginning through stop-1
4a[:] # a copy of the whole array
5