Python Lists Explained (Beginner Guide)
A Python list is one of the most useful data types for beginners to learn.
A list lets you store multiple values in one variable, keep them in order, and change them later. This makes lists a good choice when you need to work with groups of related data such as names, numbers, scores, file paths, or user input.
This guide explains what a list is, how to create one, how to access and change items, and the most common things beginners do with lists.
fruits = ["apple", "banana", "orange"]
print(fruits)
print(fruits[0])
fruits.append("grape")
print(fruits)
Output:
['apple', 'banana', 'orange']
apple
['apple', 'banana', 'orange', 'grape']
This example shows three important ideas:
- A list uses square brackets
[] - You can get one item with an index like
fruits[0] - A list can grow with methods like
append()
What a Python list is #
A Python list is an ordered collection of items.
Here are the main ideas:
- A list stores multiple values in one variable
- List items are written inside square brackets:
[] - Items are separated with commas
- A list keeps items in order
- Lists are mutable, which means you can change them after creation
Example:
numbers = [10, 20, 30]
print(numbers)
Output:
[10, 20, 30]
If you want a step-by-step page just on creating lists, see creating a Python list.
Why beginners use lists #
Lists are useful because they help you work with many related values at once.
Beginners often use lists to:
- Store many related values in one place
- Loop through items one by one
- Add or remove items as a program runs
- Keep track of names, numbers, scores, file paths, and user input
Example:
scores = [85, 90, 78, 92]
print(scores)
Instead of creating four separate variables, you can keep all the scores in one list.
How to create a list #
You can create a list in different ways.
Create an empty list #
items = []
print(items)
Output:
[]
Create a list with starting values #
colors = ["red", "green", "blue"]
print(colors)
Lists can store different types #
A list can hold strings, numbers, booleans, and other objects.
mixed = ["Alice", 25, True]
print(mixed)
This works, but beginners should usually keep related data together. A list of all names or all numbers is easier to understand than a list with unrelated values mixed together.
How list indexing works #
Each item in a list has a position called an index.
Important rules:
- The first item has index
0 - The second item has index
1 - Negative indexes count from the end
- Using an index that does not exist causes an
IndexError
Example:
fruits = ["apple", "banana", "orange"]
print(fruits[0]) # first item
print(fruits[1]) # second item
print(fruits[-1]) # last item
Output:
apple
banana
orange
fruits[0] is the first item; fruits[-1] is the last item, orange.What happens if the index does not exist? #
letters = ["a", "b"]
print(letters[5])
This raises an error because index 5 is not in the list.
If you need help with that error, see IndexError: list index out of range.
How to change list items #
Because lists are mutable, you can change an item by assigning a new value to its index.
fruits = ["apple", "banana", "orange"]
fruits[1] = "grape"
print(fruits)
Output:
['apple', 'grape', 'orange']
The original list changes.
This is different from strings, which cannot be changed in place. If you want to understand that difference better, read mutability in Python: mutable vs immutable types.
Common list operations #
Here are some of the most common things you will do with lists.
Add one item with append() #
fruits = ["apple", "banana"]
fruits.append("orange")
print(fruits)
Output:
['apple', 'banana', 'orange']
For more detail, see the Python list append() method.
Add many items with extend() #
fruits = ["apple", "banana"]
fruits.extend(["orange", "grape"])
print(fruits)
Output:
['apple', 'banana', 'orange', 'grape']
Insert at a specific position with insert() #
fruits = ["apple", "orange"]
fruits.insert(1, "banana")
print(fruits)
Output:
['apple', 'banana', 'orange']
Remove by value with remove() #
fruits = ["apple", "banana", "orange"]
fruits.remove("banana")
print(fruits)
Output:
['apple', 'orange']
Remove by position with pop() #
fruits = ["apple", "banana", "orange"]
removed_item = fruits.pop(1)
print(removed_item)
print(fruits)
Output:
banana
['apple', 'orange']
Check length with len() #
fruits = ["apple", "banana", "orange"]
print(len(fruits))
Output:
3
You can learn more on the Python list length with len().
Check membership with in #
fruits = ["apple", "banana", "orange"]
print("banana" in fruits)
print("grape" in fruits)
Output:
True
False
Looping through a list #
A for loop is the most common way to read each item in a list.
fruits = ["apple", "banana", "orange"]
for fruit in fruits:
print(fruit)
Output:
apple
banana
orange
Use this when you want to process items one by one.
Use enumerate() when you need index and value #
fruits = ["apple", "banana", "orange"]
for index, fruit in enumerate(fruits):
print(index, fruit)
Output:
0 apple
1 banana
2 orange
For a task-focused guide, see how to loop through a list in Python.
List slicing basics #
Slicing lets you get part of a list.
Use this format:
my_list[start:stop]
Rules to remember:
- Slicing gets part of a list
- Use
start:stopsyntax - The stop position is not included
- Slicing creates a new list
Example:
numbers = [10, 20, 30, 40, 50]
print(numbers[1:4])
Output:
[20, 30, 40]
This starts at index 1 and stops before index 4.
More examples are on Python list slicing explained.
Lists vs tuples, sets, and dictionaries #
Lists are not the only collection type in Python.
Use a:
- List when order matters and values may change
- Tuple for fixed data
- Set for unique items
- Dictionary for key-value pairs
Simple examples:
my_list = ["apple", "banana"]
my_tuple = ("apple", "banana")
my_set = {"apple", "banana"}
my_dict = {"name": "Alice", "age": 25}
If you are not sure which one to use, read when to use lists vs tuples vs sets vs dictionaries.
Beginner mistakes to avoid #
These are some common list mistakes:
- Forgetting that indexes start at
0 - Trying to access an item that is not in the list
- Confusing
append()withextend() - Changing a list when you meant to make a copy
- Using parentheses
()instead of square brackets[]
Here are a few common causes of problems:
- Using
list[1]when the list has only one item - Expecting
append()to add multiple separate items - Assuming lists cannot be changed after creation
- Mixing up
remove()andpop() - Forgetting that negative indexes start from the end
If something is not working, these quick checks often help:
print(my_list)
print(len(my_list))
print(my_list[0])
print(type(my_list))
for index, value in enumerate(my_list):
print(index, value)
These can help you see:
- What is actually in the list
- How many items it has
- Whether it is really a list
- Which index each item has
✍️ Try it yourself
Start with the list colors = ["red", "green", "blue"]. Append "yellow" to the end, then change the second item to "purple". Print the final list and its length.
Show answer
colors = ["red", "green", "blue"]
colors.append("yellow")
colors[1] = "purple"
print(colors)
print(len(colors))
Output:
['red', 'purple', 'blue', 'yellow']
4
FAQ #
What is a Python list? #
A Python list is an ordered collection of items that can be changed after it is created.
Can a Python list store different data types? #
Yes. A list can store strings, numbers, booleans, and other objects together.
Do Python lists start at index 0? #
Yes. The first item in a list is at index 0.
What happens if I use an index that does not exist? #
Python raises an IndexError, usually with the message list index out of range.
What is the difference between append() and extend()? #
append() adds one item to the end of the list. extend() adds each item from another iterable.
When should I use a list instead of a tuple? #
Use a list when you need to change, add, or remove items.