bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python - Remove List Items

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python - Remove List Items?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ = ["apple", "banana", "cherry"]
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The remove() method removes the specified item.
Remove Specified Index
Remove Specified Item

Remove Specified Item

The remove() method removes the specified item.

Example

thislist = ["apple", "banana", "cherry"]

thislist.remove("banana")

print(thislist)

If there are more than one item with the specified value, the remove() method removes the first occurrence:

Example

thislist = ["apple", "banana", "cherry", "banana", "kiwi"]

thislist.remove("banana")

print(thislist)

Remove Specified Index

The pop() method removes the specified index.

Example

thislist = ["apple", "banana", "cherry"]

thislist.pop(1)

print(thislist)

If you do not specify the index, the pop() method removes the last item.

Example

thislist = ["apple", "banana", "cherry"]

thislist.pop()

print(thislist)

The del keyword also removes the specified index:

Example

thislist = ["apple", "banana", "cherry"]

del
thislist[0]
print(thislist)

The del keyword can also delete the list completely.

Example

thislist = ["apple", "banana", "cherry"]

del
thislist

Clear the List

The clear() method empties the list.

The list still remains, but it has no content.

Example

thislist = ["apple", "banana", "cherry"]

thislist.clear()
print(thislist)

Previous

Python - Add List Items

Next

Python - Loop Lists