4.2.4 Mutating List Elements by Index

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

# Mutate list elements in-place using item assignment
inventory = ["laptop", "mouse", "keyboard"]

# 1. Upgrade "mouse" (index 1) to "wireless mouse"
inventory[1] = "wireless mouse"

# 2. Update the last item (index -1) to "mechanical keyboard"
inventory[-1] = "mechanical keyboard"

print("Updated inventory:", inventory)
Open in Live Interactive Python Sandbox →