Python Lists: A Complete Beginner Guide
Table of Contents
A natural way to organize and store data is in a list. Some languages call them “arrays”, but in Python we just call them lists. Think of all the apps you use and how many of the items in them are organized into lists — a social media feed is a list of posts, an online store is a list of products, the state of a chess game is a list of moves.
All the content from our Boot.dev courses are available for free here on the blog. This one is the “Lists” chapter of Learn to Code in Python. If you want to try the far more immersive version of the course, do check it out!
How Do You Create a List in Python?
Lists are declared using square brackets, with commas separating each item:
inventory = ["Iron Breastplate", "Healing Potion", "Leather Scraps"]
Lists can contain items of any data type. When a list gets long, you can break it across multiple lines for readability:
flower_types = [
"daffodil",
"rose",
"chrysanthemum",
]
This is just a styling change — the code runs the same either way. You can also start with an empty list and fill it later:
cards = []
Note: If you’re coming from another language and searching for “Python arrays” — you’re in the right place. Python’s
listis the equivalent of arrays in most other languages.
How Does List Indexing Work in Python?
Each item in a list has an index — a number that refers to its position. Indexes start at 0, not 1:
names = ["Bob", "Lane", "Alice", "Breanna"]
| Index | Value |
|---|---|
| 0 | "Bob" |
| 1 | "Lane" |
| 2 | "Alice" |
| 3 | "Breanna" |
You access items by their index using bracket notation:
best_languages = ["JavaScript", "Go", "Rust", "Python", "C"]
print(best_languages[1]) # Go
You can also update an item at a given index:
inventory = ["Leather", "Iron Ore", "Healing Potion"]
inventory[0] = "Leather Armor"
# ['Leather Armor', 'Iron Ore', 'Healing Potion']
Negative indexes count from the end: my_list[-1] gives you the last item, my_list[-2] gives the second to last, and so on.
How Do You Get the Length of a List?
The len() function returns how many items are in a list:
fruits = ["apple", "banana", "pear"]
length = len(fruits) # 3
The length is always one greater than the last index, because indexing starts at 0. This is useful when you need the last index: it’s always len(my_list) - 1.
How Do You Add Items to a List?
The .append() method adds a single item to the end of a list:
cards = []
cards.append("nvidia")
cards.append("amd")
# ['nvidia', 'amd']
It’s common to create an empty list then fill it with values using a loop. You can also combine two lists using the + operator:
total = [1, 2, 3] + [4, 5, 6]
print(total) # [1, 2, 3, 4, 5, 6]
How Do You Remove Items From a List?
The .pop() method removes the last element from a list and returns it:
vegetables = ["broccoli", "cabbage", "kale", "tomato"]
last = vegetables.pop()
# vegetables = ['broccoli', 'cabbage', 'kale']
# last = 'tomato'
You can also pass an index to .pop() to remove an item at a specific position: vegetables.pop(1) would remove "cabbage".
The del keyword deletes items by index or slice:
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
del nums[3] # [1, 2, 3, 5, 6, 7, 8, 9]
del nums[1:3] # [1, 5, 6, 7, 8, 9]
To check if an item exists before removing it, use the in keyword:
fruits = ["apple", "orange", "banana"]
print("banana" in fruits) # True
How Do You Loop Over a List in Python?
You can loop over a list using an index with range() and len():
sports = ["soccer", "basketball", "baseball"]
for i in range(0, len(sports)):
print(sports[i])
But Python has a much cleaner syntax when you don’t need the index — just iterate directly over the items:
trees = ["oak", "pine", "maple"]
for tree in trees:
print(tree)
# oak
# pine
# maple
The variable tree takes on each value in the list directly, no index needed. This is the preferred style in Python when you only need to read the values.
How Does List Slicing Work in Python?
Python’s slicing operator lets you grab a section of a list. It returns a new list:
my_list[start:stop:step]
All three sections are optional:
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[:3] # [0, 1, 2]
numbers[3:] # [3, 4, 5, 6, 7, 8, 9]
numbers[::2] # [0, 2, 4, 6, 8]
numbers[-3:] # [7, 8, 9]
Like range(), the start is inclusive and stop is exclusive. You can reverse a list with a negative step:
numbers = [1, 2, 3, 4, 5]
reversed_numbers = numbers[::-1] # [5, 4, 3, 2, 1]
What Is a Tuple in Python?
Tuples are like lists but immutable — once created, you can’t change them. They’re declared with parentheses:
my_tuple = ("this is a tuple", 45, True)
print(my_tuple[0]) # this is a tuple
print(my_tuple[1]) # 45
Tuples are great for small, fixed groups of data — like a name and age pair:
dog = ("Fido", 4)
dog_name, dog_age = dog
print(dog_name) # Fido
print(dog_age) # 4
That second example uses tuple unpacking to assign each value to its own variable. When you return multiple values from a function, you’re actually returning a tuple.
For single-item tuples, you need a trailing comma so Python doesn’t treat the parentheses as grouping:
single = ("Fido",)
What Should You Learn After Python Lists?
Lists are used everywhere in Python, so now is a great time to get comfortable with loops and conditionals if you haven’t already — they’re what make lists truly powerful. From here, most beginners move on to dictionaries (another core data structure) and string manipulation.
If you want to keep going through the full Python curriculum with hands-on exercises, check out the Learn to Code in Python course on Boot.dev.
Frequently Asked Questions
What is the difference between a list and an array in Python?
In Python, lists are the built-in sequence type and they are what most other languages call arrays. Python does have a separate array module for numeric data, but in practice almost everyone uses lists. If you see someone say python array they almost certainly mean a list.
Can a Python list hold different data types?
Yes. A single list can contain strings, integers, floats, booleans, and even other lists. That said, it is generally considered better practice to keep a list to one type so your code is easier to reason about.
What is the difference between append and extend in Python?
append adds a single item to the end of a list. extend takes an iterable and adds each of its elements individually. For example, my_list.append([1, 2]) adds one item (the list [1, 2]), while my_list.extend([1, 2]) adds two items (1 and 2).
What is the difference between a list and a tuple in Python?
Lists are mutable, meaning you can add, remove, and change items after creation. Tuples are immutable and have a fixed size. Use tuples for small, fixed groups of related data and lists when the collection needs to change.
Related Articles
Python Loops: For, While, Break, and Continue
Mar 04, 2026 by lane
Loops let you run the same code over and over without rewriting it each time. Whether you need to count through numbers, process items in a list, or keep going until a condition changes, Python gives you for loops and while loops to handle it.
Python If Statements: If, Else, and Elif
Mar 03, 2026 by lane
Every useful program needs to make decisions. Python’s if statement is how you tell your code to do one thing or another depending on some condition — and once you understand if, elif, and else, you can handle just about any branching logic.
Python Math: Operators and Numbers Explained
Mar 02, 2026 by lane
Python has excellent built-in support for math operations — from basic arithmetic to exponents to bitwise logic. You don’t need to import anything to do most math in Python, which is one reason it’s so popular for everything from backend development to data science.
Python Functions: How to Define and Call Them
Mar 01, 2026 by lane
Functions allow you to reuse and organize code. Instead of copying and pasting the same logic everywhere, you define it once and call it whenever you need it. They’re the most important tool for writing DRY code.