Python18 min read
Python Lists
Master lists: indexing, slicing, updating, looping, and common list methods with outputs.
Emily Davis
August 14, 2025
7.8k236
Lists store multiple values in one variable. They are ordered, and they are mutable (you can change them).
Lists are used everywhere:
- storing names
- storing items in a cart
- storing results from a database
- storing rows in a CSV file
Create a list
cities = ["Miami", "Austin", "Denver"]
print(cities)
Expected output:
['Miami', 'Austin', 'Denver']
Indexing (get items)
cities = ["Miami", "Austin", "Denver"]
print(cities[0])
print(cities[1])
print(cities[-1])
Expected output:
Miami
Austin
Denver
Slicing (get part of list)
numbers = [10, 20, 30, 40, 50]
print(numbers[1:4])
Expected output:
[20, 30, 40]
Updating a list
fruits = ["apple", "banana"]
fruits.append("orange")
print(fruits)
fruits.remove("banana")
print(fruits)
fruits[0] = "grape"
print(fruits)
Expected output:
['apple', 'banana', 'orange']
['apple', 'orange']
['grape', 'orange']
Sorting (and why it matters)
numbers = [3, 1, 4, 1, 5]
numbers.sort()
print(numbers)
Expected output:
[1, 1, 3, 4, 5]
Graph: list operations
flowchart LR
A[List] --> B[Index access]
A --> C[Slicing]
A --> D[append/remove]
A --> E[sort]
In the next lesson, you will learn if statements, how conditions work, and how to build decision logic correctly.
#Python#Beginner#Lists