📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero Lists

Lists

5 min read Quiz at the end
Lists are ordered, mutable collections: [1, 2, 3]. Use append() to add, pop() to remove, and len() for the count. List comprehensions like [x*2 for x in range(10)] create new lists very concisely.

Python Lists

fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
fruits.insert(0, "avocado")
fruits.remove("banana")
print(fruits[0])      # avocado
print(fruits[-1])     # mango
print(fruits[1:3])    # slice
print(len(fruits))

# List comprehension
squares = [x**2 for x in range(10)]
Topic Quiz · 5 questions

Test your understanding before moving on

1. Which method adds an item to the end of a list?
💡 .append() adds an item to the end of a list.
2. How do you get the last element of a list?
💡 Negative indexing: list[-1] returns the last element.
3. What does list[1:3] return?
💡 Slicing [1:3] returns elements at index 1 and 2 (not 3).
4. Which creates a list with squares 0-9?
💡 List comprehension [x**2 for x in range(10)] creates [0, 1, 4, 9, ...].
5. How do you remove an item by value?
💡 .remove(value) finds and removes the first occurrence of the value.