Recall & Review
beginner
How do you add an element to the end of a list in Python?
Use the
append() method. For example, my_list.append(5) adds 5 to the end of my_list.Click to reveal answer
beginner
What method removes and returns the last element from a list?
The
pop() method removes and returns the last element. For example, item = my_list.pop() removes the last item and stores it in item.Click to reveal answer
intermediate
How can you add an element at a specific position in a list?
Use the
insert(index, element) method. It adds the element at the given index, shifting others to the right. Example: my_list.insert(1, 'a') adds 'a' at position 1.Click to reveal answer
beginner
How do you remove a specific element by value from a list?
Use the
remove(value) method. It deletes the first occurrence of the value. Example: my_list.remove(3) removes the first 3 found.Click to reveal answer
intermediate
What happens if you try to remove an element that is not in the list using
remove()?Python raises a
ValueError because the element is not found in the list.Click to reveal answer
Which method adds an element to the end of a list?
✗ Incorrect
The
append() method adds an element to the end of the list.What does
pop() do when called without arguments?✗ Incorrect
pop() removes and returns the last element of the list.How do you add an element at index 2 in a list?
✗ Incorrect
Use
insert(index, element) to add at a specific position.Which method removes the first occurrence of a value from a list?
✗ Incorrect
remove(value) deletes the first matching value from the list.What error occurs if you try to remove a value not in the list?
✗ Incorrect
Trying to remove a non-existent value raises a
ValueError.Explain how to add elements to a Python list and the difference between
append() and insert().Think about adding items to a shopping list either at the end or in the middle.
You got /3 concepts.
Describe the ways to remove elements from a list and what happens if you remove a value not present.
Consider taking items off a shelf by position or by name.
You got /3 concepts.