Editor

Access the Last Item with Negative Indexing

Beginner · Write the code · from Python Lists: Create, Access, Modify, and Loop Through Lists

From the lesson: Python Lists: Create, Access, Modify, and Loop Through Lists

Think about your favorite music playlist. It has a bunch of songs stored in a specific order. You can add new songs, remove old ones, rearrange them, or skip to song number five.

Read the lesson

A list of cities is given. Use negative indexing to print the last city in the list.

Expected output:

Tokyo
cities = ["Paris", "London", "New York", "Tokyo"]
# Print the last city using negative indexing

More Lists exercises

All Python exercises · 50 practice problems · Data Structures quiz