List Basics
Indexing
Adding items
Removing items
Predict the Output
100

What is a list [ ]

A collection of items stored in a variable using brackets [].

100

What does this print?

animals = ["cat","dog","mouse"]
print(animals[2])

mouse

100

What does the list method .append do?

animals.append("horse")

adds horse to the end of a list

100

What does this do?

animals.remove("cat")


Removes "cat" from the list.

100

pets = ["cat","dog"]
pets.append("fish")
print(pets)

["cat","dog","fish"]

200

What does this code print? 

animals = ["cat","dog","mouse"]

print(animals)

["cat","dog","mouse"]

200

What does this print?

animals = ["cat","dog","mouse"]
animals[1] = "cow"
print(animals)

["cat","cow","mouse"]

200

What does .insert do?

animals.insert(2,"pig")

Adds "pig" at index 2.

200

What does this do? 

animals.pop(2)

Removes the item at index 2.

200

pets = ["cat","dog","mouse"]
pets.pop(1)
print(pets)

["cat","mouse"]

300

How do you access the first item in a list?

list[0]

300

Which index refers to "dog"?

1

300

What does this do?

list1.extend(list2)



Adds all items from list2 to list1.

300

What happens?

x = animals.pop(2)

print(x)



Removes the item at an index 2, stores it in x, prints x

300

pets = ["cat","dog","mouse"]
pets.remove("dog")
print(pets)

["cat","mouse"]

400

What does this print? 

animals = ["cat","dog","mouse"]
print(animals[1])

dog

400

What does this print?

nums = [10,20,30,40]
print(nums[-1])

40

400

What is the output?

nums = [1,2,3]

nums.append(4)

[1,2,3,4]

400

What is the difference between .remove() and .pop()? 

  • remove() removes by value

  • pop() removes by index

400

pets = ["cat","dog","mouse"]
pets.insert(1,"bird")
print(pets)

["cat","bird","dog","mouse"]

500

True or False: Lists can store multiple data items.

True

500

What does negative indexing do?

counts from the end of the list
500

What is the difference between .insert() and .append()? 

  • append() adds to end

  • insert() adds at a specific index

500

What does this do?

if "lion" in animals:
    animals.remove("lion")

Check if "lion" is in the list first and then removes it.

500

pets = ["cat","dog","mouse"]
x = pets.pop(1)
print(x)

dog

M
e
n
u