Python's list is the most flexible built-in sequence type — ordered, mutable, and able to hold any mix of values. If you are writing Python for the first time and need to store a collection of items in a predictable sequence, a list is where you start.
Python stores list items in the order you define them, and that order stays consistent unless you explicitly change it. This makes lists ideal for things like a ranked sequence of results, a queue of tasks to process, or any situation where position carries meaning. This tutorial walks through every foundational skill you need to start working with Python lists from scratch.
What is an Ordered List in Python?
When Python documentation describes a list as ordered, it means the sequence is positional — each item has a fixed numeric index, and that index determines where Python looks when you ask for a value. The first item is always at position zero, the second at position one, and so on. Add a new item to the end and it takes the next available position. That positional structure never changes unless you sort, reverse, or restructure the list yourself.
This is different from a set, which discards duplicates and has no guaranteed position, or a dict, which organizes data around keys rather than positions. When order matters and you need to be able to add or change items freely, a list is the right choice.
Python lists preserve insertion order — the sequence you add items is the sequence they are stored. This guarantee has been part of the language since the beginning and holds across all Python versions you are likely to encounter.
Python's list is also mutable. That means you can change any item at any index, add new items, or remove existing ones after the list has been created. This is what separates a list from a tuple, which is ordered but cannot be changed once it is created.
Lists vs. Other Sequence Types
Understanding when to use a list versus another sequence type helps from the start. The accordion below compares the three you will encounter first.
- Ordered
- Yes — items keep the position they were inserted at
- Mutable
- Yes — items can be added, removed, or replaced after creation
- Ordered
- Yes — positional like a list
- Mutable
- No — once created, a tuple cannot be changed
- Ordered
- No — items have no defined position
- Mutable
- Yes — items can be added or removed, but no duplicates are allowed
Creating a List and Accessing Items
Creating a list takes one line. Write a variable name, assign it with =, and place your values inside square brackets separated by commas. Python infers the type automatically — you do not need to declare it.
# A list of planet names in order from the Sun
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter']
# A list of integers
scores = [88, 72, 95, 61, 84]
# A mixed-type list (valid in Python)
record = ['Alice', 34, True, 9.5]
# An empty list — populate it later
tasks = []
Start with an empty list and append() items when you do not know all the values upfront. This pattern is common when reading data from a file, a loop, or user input.
Indexing: Accessing Items by Position
To retrieve a specific item, write the list name followed by its index inside square brackets. Remember that Python counts from zero, not one.
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter']
print(planets[0]) # Mercury — first item
print(planets[2]) # Earth — third item
print(planets[-1]) # Jupiter — last item (negative index)
print(planets[-2]) # Mars — second-to-last item
Negative indices count backward from the end of the list. Index -1 is always the last item regardless of how long the list is. This saves you from writing planets[len(planets) - 1] every time.
Slicing: Extracting a Range of Items
Slicing returns a new list containing a subset of the original. The syntax is list[start:stop] where start is inclusive and stop is exclusive.
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter']
inner_planets = planets[0:4] # ['Mercury', 'Venus', 'Earth', 'Mars']
last_two = planets[3:] # ['Mars', 'Jupiter'] — omit stop to go to end
first_three = planets[:3] # ['Mercury', 'Venus', 'Earth'] — omit start for index 0
all_copy = planets[:] # a full shallow copy of the list
Build the statement that accesses the last item in a list called colors using negative indexing:
-1 for the last item. colors[-1] retrieves the final element without needing to know the list length. Using colors[0] would give the first item, not the last, and colors[1] gives the second item.
Modifying a List: Add and Remove Items
Because lists are mutable, Python gives you several methods to change their contents after creation. The four you will use most often as a beginner are append(), insert(), remove(), and pop().
tasks = ['write tests', 'review PR', 'deploy']
# append() — adds to the end
tasks.append('update docs')
# tasks is now ['write tests', 'review PR', 'deploy', 'update docs']
# insert(index, value) — adds at a specific position
tasks.insert(1, 'fix linting')
# tasks is now ['write tests', 'fix linting', 'review PR', 'deploy', 'update docs']
# remove(value) — deletes the first match
tasks.remove('review PR')
# tasks is now ['write tests', 'fix linting', 'deploy', 'update docs']
# pop(index) — removes and returns the item at that index
completed = tasks.pop(0)
print(completed) # write tests
# tasks is now ['fix linting', 'deploy', 'update docs']
Calling remove() with a value that does not exist in the list raises a ValueError. Before removing a value, check that it exists: if 'value' in my_list: or use a try/except block.
Iterating Over a List
A for loop processes every item in the list in order, from index zero to the last index. You do not need to manage the index manually.
scores = [88, 72, 95, 61, 84]
# Simple iteration
for score in scores:
print(score)
# Iteration with index using enumerate()
for index, score in enumerate(scores):
print(f'Student {index + 1}: {score}')
# Output:
# Student 1: 88
# Student 2: 72
# Student 3: 95
# Student 4: 61
# Student 5: 84
enumerate() pairs each item with its index as you iterate, which avoids the need to write a separate counter variable. The index starts at zero by default, but you can pass a second argument to start from a different number: enumerate(scores, start=1).
The code below tries to print the third planet in the list. It runs without a syntax error but prints the wrong value. Click the line you think is wrong.
planets[3] to planets[2]. Python lists use zero-based indexing, so the first item is at index 0, the second at index 1, and the third — "Earth" — is at index 2. Index 3 points to "Mars", which is the fourth item.
Useful Built-in List Functions
Python provides a set of built-in functions that work directly on lists without needing to import anything.
| Function / Method | What It Does | Example |
|---|---|---|
len(lst) |
Returns the number of items | len([1, 2, 3]) → 3 |
sorted(lst) |
Returns a new sorted list without changing the original | sorted([3, 1, 2]) → [1, 2, 3] |
lst.sort() |
Sorts the list in place (modifies the original) | lst.sort() |
lst.reverse() |
Reverses the list in place | lst.reverse() |
lst.count(val) |
Counts occurrences of a value | [1,1,2].count(1) → 2 |
lst.index(val) |
Returns the index of the first occurrence | ['a','b'].index('b') → 1 |
"Lists are mutable sequences, typically used to store collections of homogeneous items." — Python Software Foundation
How to Create an Ordered List in Python
The five steps below cover the complete workflow: creating a list, reading from it, adding to it, removing from it, and iterating over it. Each step maps to a specific Python operation you will use regularly.
-
Define the list with square brackets
Write the variable name, assign it with
=, and place your comma-separated values inside[ ]. Strings go in quotes; numbers do not. An empty list is written as[]. -
Access items by index
Use
my_list[0]for the first item,my_list[1]for the second, and so on. Use negative indices likemy_list[-1]to count from the end without knowing the total length. -
Add items with append() or insert()
Call
my_list.append(value)to add to the end, ormy_list.insert(index, value)to place an item at a specific position. Items after the insertion point shift one position to the right. -
Remove items with remove() or pop()
Use
my_list.remove(value)to delete the first occurrence of a value. Usemy_list.pop(index)to remove and return a specific item.pop()with no argument removes the last item. -
Iterate over the list with a for loop
Write
for item in my_list:to process each element in order. Addenumerate()to get both the index and the value in a single loop variable pair:for i, item in enumerate(my_list):.
Python Ordered List Summary Points
- A Python list is ordered, meaning items keep the position they were inserted at, and that position is referenced by a zero-based integer index.
- Lists are mutable — you can add, remove, or replace any item at any time using methods like
append(),insert(),remove(), andpop(). - Negative indexing (
-1,-2, etc.) accesses items from the end of the list without needing to know its length, and slicing (list[start:stop]) returns a new list from a range of positions.
Lists are the starting point for almost every data-handling task you will write in Python. Once you are comfortable with indexing, slicing, and the core add/remove methods, you are ready to move on to list comprehensions, sorting with key functions, and working with nested lists.
Frequently Asked Questions
An ordered list in Python is a list where the position of each item is fixed and preserved. Python's built-in list type is ordered by default, meaning the sequence in which you add items is the sequence in which they are stored and retrieved.
You create a list in Python by enclosing comma-separated values inside square brackets. For example: my_list = ['apple', 'banana', 'cherry']. You can also create an empty list with my_list = [] and add items later.
In Python, list indexing starts at 0. Index 0 refers to the first item in the list. So for a list fruits = ['apple', 'banana', 'cherry'], fruits[0] returns 'apple'.
Use the append() method to add a single item to the end of a list. For example: my_list.append('new item'). To add an item at a specific position, use insert(index, value).
append() always adds an item to the end of a list and takes a single argument — the item to add. insert() adds an item at a specific index position and takes two arguments: the index and the item.
Yes. Python lists are heterogeneous, meaning a single list can contain strings, integers, floats, booleans, and even other lists. For example: mixed = ['hello', 42, 3.14, True] is a valid Python list.
Use remove(value) to delete the first matching item by value, or pop(index) to remove an item by its position and return it. Calling pop() with no argument removes the last item.
Negative indexing lets you access list items from the end. Index -1 refers to the last item, -2 to the second-to-last, and so on. For a list with three items, index -1 and index 2 point to the same element.
Use the built-in len() function. For example, len(my_list) returns the total number of items in the list as an integer.
List slicing lets you extract a portion of a list using the syntax list[start:stop]. The start index is inclusive and the stop index is exclusive. For example, fruits[0:2] returns the first two items.