4.2.6 Inserting at a Specific Index: insert()

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

# Insert items at chosen index positions in the inventory list
inventory = ["laptop", "wireless mouse", "mechanical keyboard"]

# 1. Insert "docking station" at the very beginning (index 0)
inventory.insert(0, "docking station")

# 2. Insert "mousepad" between "wireless mouse" and "mechanical keyboard" (at index 2)
inventory.insert(2, "mousepad")

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