Lists

A list contains an ordered collection of elements. To create a list, use a pair of square brackets. To create an empty list, leave the brackets empty. To create a list with elements, put values inside of the brackets. Examples:
x = []
print(x)
# []

x = ["a", "b", "c"]
print(x)
# ["a", "b", "c"]
To add an element to the end of a list, use the .append() method:
x = ["a", "b", "c"]
x.append("d")
print(x)
# ["a", "b", "c", "d"]
To remove a specific value from a list, use the .remove() method:
x = ["a", "b", "c"]
x.remove("b")
print(x)
# ["a", "c"]
To remove an element at a specific position from a list, use the del keyword with the index of the element. Indexes start at 0:
x = ["a", "b", "c"]
del x[0]
print(x)
# ["b", "c"]

Exercise 1 of 10

Initialize an empty list called numbers.

Your code

Exercise 2 of 10

Initialize an empty list called words.

Your code

Exercise 3 of 10

Initialize a list called fruits that contains the values "apple", "pear", and "plum".

Your code

Exercise 4 of 10

Initialize a list called names that contains the values "Olivia", "Noah", and "Michael".

Your code

Exercise 5 of 10

Add the number 3 to the list.
numbers = [1, 2]

Your code

Exercise 6 of 10

Add the value "c" to the list.
letters = ["a", "b"]

Your code

Exercise 7 of 10

Remove the number 1.4 from the list.
numbers = [1.1, 1.2, 1.3, 1.4, 1.5]

Your code

Exercise 8 of 10

Remove the word "chair" from the list.
items = ["table", "chair", "counter", "stove"]

Your code

Exercise 9 of 10

Remove the first value from a list called numbers.

Your code

Exercise 10 of 10

Remove the fifth value from a list called places.

Your code