4.2.7 Deleting by Value: remove()

Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Remove items from the list by matching value
inventory = ["docking station", "laptop", "mousepad", "wireless mouse", "mechanical keyboard"]

# 1. Remove "mousepad" from the list
inventory.remove("mousepad")

# 2. Check membership before removal to avoid errors
target = "docking station"
if target in inventory:
    inventory.remove(target)

print("Inventory after remove operations:", inventory)
Open in Live Interactive Python Sandbox →