Beginning Python

We make a list and then select a few slices of it:

list.py
my_list = [3, 5, "green", 5.3, "house", 100, 1]

print(my_list[2:4])
print(my_list[3:-2])
print(my_list[0:1])
print(my_list[-4:-1])

This selects everything from the number 2 index up to, but not including the number 4 index, i.e. the 2 and 3 indexes:

[2:4]

This starts at index 3 and goe as far as index -2 (which is the same as index 5 in this list):

[3:-2]

This starts at the beginning of the list and stops before index 1, giving us a list with just one item:

[0:1]

This starts at index -4 (i.e. index 3) and goes until index -1 (i.e. index 6):

[-4:-1]
$
python list.py
['green', 5.3]
[5.3, 'house']
[3]
[5.3, 'house', 100]