Previous Lesson Current Lesson Next Lesson

Question 1

l = [23, "dog", 5]

Take the Python object elements, separate them with commas, and surround with brackets. Python will do the rest of the (hard) work for you.

Question 2

Building on from the previous solution, we have:

l = [23, "dog", 5]
l.append("cat")
l.remove(23)

To append an element, use the append method. To remove an element, use the remove method. That’s it! The new list should be: ["dog", 5, "cat"].

Question 3

Building on from the previous solution, we have:

l = [23, "dog", 5]
l.append("cat")
l.remove(23)
print(l[0])

This will output:

'dog'

Remember, to access the nth element of a list, we must use n - 1 as the index. In this case, we want the first element, so we must use the index 1 - 1 = 0.