4.2.8 Removing and Returning Elements: pop()

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):

# Pop elements from specific index positions in the list
inventory = ["laptop", "wireless mouse", "mechanical keyboard", "monitor"]

# 1. Pop the last item (default index -1)
last_item = inventory.pop()

# 2. Pop the item at index 1 ("wireless mouse")
removed_item = inventory.pop(1)

print("Popped last item:", last_item)
print("Popped index 1 item:", removed_item)
print("Remaining inventory:", inventory)
Open in Live Interactive Python Sandbox →