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

# Access elements from the inventory list
inventory = ["laptop", "mouse", "keyboard", "monitor", "headphones"]

# 1. Access the first item (index 0)
first_item = inventory[0]

# 2. Access the third item (index 2)
third_item = inventory[2]

# 3. Access the last item using negative index -1
last_item = inventory[-1]

print("First item:", first_item)
print("Third item:", third_item)
print("Last item:", last_item)
Open in Live Interactive Python Sandbox →