|
| Home |
|---|
The Python list append() method is used to add a single
item to the end of a Python list. The append()
method is one of the most frequently used Python list methods and is
especially useful when a program needs to build or update a list
dynamically.
If you are learning Python lists, understanding how
append() works is essential. You will commonly use it when
collecting values in a loop, storing user input, building results,
processing data, creating nested lists, and constructing datasets.
The append() method in Python adds one item to the end of an existing list. The new item is placed after the last element currently in the list.
For example, if a list contains:
numbers = [10, 20, 30]
and you use:
numbers.append(40)
the list becomes:
[10, 20, 30, 40]
The important point is that append() adds
one object to the list. That object can be a number,
string, Boolean value, tuple, dictionary, another list, or another
Python object.
The syntax of the Python list append() method is:
list.append(element)
Here:
For example:
numbers.append(50)
This adds 50 to the end of the numbers list.
The simplest way to append an item to a Python list is to call
append() on the list and provide the item as its argument.
numbers = [10, 20, 30]
numbers.append(40)
print(numbers)
[10, 20, 30, 40]
The original list contained three elements. After calling
append(40), the list contains four elements and
40 is the last item.
You can use append() to add integers or floating-point
numbers to a list.
numbers = [10, 20, 30]
numbers.append(40)
print(numbers)
[10, 20, 30, 40]
The value 40 is appended to the end of the list.
The append() method can also add strings to a Python list.
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits)
['apple', 'banana', 'cherry', 'orange']
Here, the string "orange" becomes the fourth element in
the list.
Python lists can contain Boolean values such as True and
False.
answers = [True, False, True]
answers.append(False)
print(answers)
[True, False, True, False]
prices = [10.50, 20.75, 15.25]
prices.append(30.99)
print(prices)
[10.5, 20.75, 15.25, 30.99]
A very common use of append() is to start with an empty
list and add elements to it as a program runs.
numbers = []
numbers.append(10)
numbers.append(20)
numbers.append(30)
print(numbers)
[10, 20, 30]
This technique is useful when the values are not known when the program starts.
One of the most important uses of append() is building a
list dynamically inside a loop.
numbers = []
for i in range(5):
numbers.append(i)
print(numbers)
[0, 1, 2, 3, 4]
The list begins empty. During each iteration of the loop, the current
value of i is appended to the list.
This pattern is extremely common in Python programming:
result = []
for item in collection:
result.append(item)
The append() method is often used to store the results of
calculations.
numbers = [1, 2, 3, 4, 5]
squares = []
for number in numbers:
squares.append(number ** 2)
print(squares)
[1, 4, 9, 16, 25]
Each square is calculated and then added to the squares
list.
You can combine append() with an if
statement to build a list containing only values that satisfy a
condition.
numbers = [5, 12, 8, 20, 3, 15]
large_numbers = []
for number in numbers:
if number >= 10:
large_numbers.append(number)
print(large_numbers)
[12, 20, 15]
Only numbers greater than or equal to 10 are appended to
the new list.
A Python list can itself be appended to another list. When this happens, the entire list is added as one element.
list1 = [1, 2, 3]
list1.append([4, 5])
print(list1)
[1, 2, 3, [4, 5]]
Notice that [4, 5] remains together as a nested list.
Python does not add 4 and 5 as separate
elements.
This behaviour is one of the most important things to understand about
append().
The object passed to append() can be a tuple.
data = [1, 2, 3]
data.append((4, 5))
print(data)
[1, 2, 3, (4, 5)]
The tuple is added as one element.
A dictionary can also be appended to a list. This is particularly useful when creating a collection of records.
students = []
students.append({"name": "Ali", "score": 85})
students.append({"name": "Sara", "score": 92})
print(students)
[{'name': 'Ali', 'score': 85}, {'name': 'Sara', 'score': 92}]
This pattern is frequently used when working with structured data, records and simple datasets in Python.
You can use append() to build a list containing multiple
student records.
students = []
students.append(["Ali", 85])
students.append(["Sara", 92])
students.append(["John", 78])
print(students)
[['Ali', 85], ['Sara', 92], ['John', 78]]
Each student record is appended as one element of the outer list.
The append() method is useful when a program collects
values from a user.
names = []
name1 = "Ali"
name2 = "Sara"
name3 = "John"
names.append(name1)
names.append(name2)
names.append(name3)
print(names)
['Ali', 'Sara', 'John']
In a real interactive program, the values could come from
input(), a form, a file, or another data source.
A common programming pattern is to process each item and append the result to a separate list.
prices = [100, 200, 300, 400]
discounted = []
for price in prices:
new_price = price * 0.90
discounted.append(new_price)
print(discounted)
[90.0, 180.0, 270.0, 360.0]
Here, append() is being used to build a new list from
calculated results.
The append() method modifies the existing list. It does
not normally create and return a new list.
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
[1, 2, 3, 4]
The original numbers list has been changed.
A common Python beginner mistake is assuming that append()
returns the updated list.
It does not. The append() method returns
None.
numbers = [1, 2, 3]
result = numbers.append(4)
print(result)
print(numbers)
None
[1, 2, 3, 4]
The list is modified, but the return value of append() is
None.
Do not write:
numbers = numbers.append(4)
This causes numbers to become None, because
the method returns None.
Instead, simply write:
numbers.append(4)
One of the most common questions when learning Python lists is the
difference between append() and extend().
| Method | What it does | Example | Result |
|---|---|---|---|
append() |
Adds one object as one element | list.append([4,5]) |
[1,2,3,[4,5]] |
extend() |
Adds elements individually | list.extend([4,5]) |
[1,2,3,4,5] |
list1 = [1, 2, 3]
list1.append([4, 5])
print(list1)
list2 = [1, 2, 3]
list2.extend([4, 5])
print(list2)
[1, 2, 3, [4, 5]]
[1, 2, 3, 4, 5]
Use append() when you want to add the object itself.
Use extend() when you want to add the elements contained
inside an iterable.
Both append() and insert() add an item to a
list, but they are used differently.
| Method | Purpose |
|---|---|
append() |
Adds an item to the end of the list |
insert() |
Adds an item at a specified position |
numbers1 = [1, 2, 3]
numbers1.append(4)
numbers2 = [1, 2, 3]
numbers2.insert(1, 4)
print(numbers1)
print(numbers2)
[1, 2, 3, 4]
[1, 4, 2, 3]
The + operator can also be used to combine lists, but it
works differently from append().
numbers = [1, 2, 3]
new_numbers = numbers + [4]
print(numbers)
print(new_numbers)
[1, 2, 3]
[1, 2, 3, 4]
The + operator creates a new list, whereas
append() modifies the existing list.
The append() method accepts only one argument. Therefore,
the following is not valid:
numbers.append(4, 5)
If you want to add multiple individual elements, use
extend():
numbers.extend([4, 5])
Alternatively, you can call append() multiple times:
numbers.append(4)
numbers.append(5)
Yes. Python lists can contain objects of different data types, and
append() can add any appropriate Python object.
items = [10, "Python", 3.14, True]
items.append([1, 2, 3])
print(items)
[10, 'Python', 3.14, True, [1, 2, 3]]
Python lists are flexible, although in real applications it is often better to keep collections logically consistent where possible.
The append() method is particularly important in loops
because it allows a program to accumulate results one item at a time.
results = []
for number in range(1, 6):
result = number * 10
results.append(result)
print(results)
[10, 20, 30, 40, 50]
This is one of the fundamental patterns used in Python programming, data processing and algorithm development.
You can use append() together with conditional statements
to collect only values that meet specific criteria.
marks = [45, 72, 88, 39, 91, 65]
passed = []
for mark in marks:
if mark >= 50:
passed.append(mark)
print(passed)
[72, 88, 91, 65]
This approach is useful for filtering data and building result lists.
The append() method is not only useful in simple examples.
It is frequently used in real Python programs whenever data needs to
be collected or accumulated.
A program can process values and append each calculated result to a new list.
Programs can append records obtained from files, APIs, databases, forms or other data sources.
Educational programs can append marks, grades or student records to lists while processing student data.
Python programs can use append() to collect calculated
statistics, filtered observations or transformed data before further
analysis.
A list can be built row by row before being converted into a DataFrame or processed by another Python library.
A program can append matching records to a result list while searching through a collection.
The following example demonstrates how append() can be
used to build a simple dataset.
data = []
data.append(["Ali", 21, 85])
data.append(["Sara", 22, 92])
data.append(["John", 20, 78])
print(data)
[['Ali', 21, 85], ['Sara', 22, 92], ['John', 20, 78]]
Each row is appended as one list inside the outer list.
Suppose a business wants to calculate revenue from units sold and price.
The calculated values can be collected using append().
units = [10, 20, 15, 30]
price = 100
revenue = []
for quantity in units:
revenue.append(quantity * price)
print(revenue)
[1000, 2000, 1500, 3000]
This demonstrates why append() is important in data
processing: the program can calculate and collect results dynamically.
numbers = range(1, 11)
even_numbers = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
print(even_numbers)
[2, 4, 6, 8, 10]
Here, append() is used to build a list containing only
numbers that satisfy the condition.
List comprehensions can sometimes replace the loop-and-append pattern. For example:
numbers = [1, 2, 3, 4, 5]
squares = [number ** 2 for number in numbers]
print(squares)
[1, 4, 9, 16, 25]
However, understanding append() first is important because
the loop-and-append pattern makes the underlying process easier to
understand.
Appending an item to the end of a Python list is generally an O(1) amortized operation. This means that adding an item is normally very efficient.
Python lists are dynamic arrays. Occasionally, the list may need to allocate additional storage when its internal capacity is reached. Although such resizing can take longer for an individual operation, the average cost of repeated appends remains efficient.
For most everyday Python programs, append() is the standard
and efficient way to add an item to the end of a list.
| Characteristic | Description |
|---|---|
| Purpose | Adds one item to the end of a list |
| Arguments | One argument |
| Changes original list | Yes |
| Return value | None |
| Can append another list? | Yes, as one nested element |
| Can append a string? | Yes, as one string element |
| Typical complexity | O(1) amortized |
This is incorrect:
numbers = numbers.append(40)
Because append() returns None, this assignment
will replace the variable with None.
Use:
numbers.append(40)
This is incorrect:
numbers.append(40, 50)
The method accepts one argument. Use:
numbers.extend([40, 50])
or:
numbers.append(40)
numbers.append(50)
Remember:
numbers.append([4, 5])
produces:
[1, 2, 3, [4, 5]]
whereas:
numbers.extend([4, 5])
produces:
[1, 2, 3, 4, 5]
The method modifies the list in place. If another variable refers to the same list, that reference will also see the modification.
numbers = [1, 2, 3]
other = numbers
numbers.append(4)
print(other)
[1, 2, 3, 4]
Use append() when you need to add one item to the
end of a list.
Typical situations include:
Use extend() when you have an iterable containing multiple
elements and you want those elements added individually to the list.
For example:
numbers = [1, 2, 3]
numbers.extend([4, 5, 6])
print(numbers)
Result:
[1, 2, 3, 4, 5, 6]
append() adds an item to the end of a list.append() becomes a nested list.append() modifies the original list.None.append() is commonly used inside loops.extend() when you need to add multiple iterable elements individually.insert() when you need to add an item at a specific position.
append() is a Python list method used to add one item to
the end of an existing list.
Call append() on the list and provide the item you want
to add. For example:
numbers = [1, 2, 3]
numbers.append(4)
It adds one new element at the end of the list and modifies the original list.
The append() method adds the new element to the
end of the list.
No. The append() method accepts one argument. To add
multiple elements individually, use extend() or call
append() multiple times.
append() adds its argument as one element, while
extend() adds the elements of an iterable individually.
Yes. When you use append() with another list, the entire
list is added as one element.
numbers = [1, 2, 3]
numbers.append([4, 5])
print(numbers)
The result is:
[1, 2, 3, [4, 5]]
The append() method returns None. It modifies
the original list rather than returning a new list.
Yes. append() modifies the existing list in place.
Yes. A string passed to append() is added as one element.
For example:
names = ["Ali", "Sara"]
names.append("John")
Yes. Using append() inside a for loop is one
of the most common ways to build a Python list dynamically.
You can use an if statement before calling
append().
numbers = []
for number in range(1, 6):
if number % 2 == 0:
numbers.append(number)
print(numbers)
This produces:
[2, 4]
No. append() always adds an item to the end of the list,
while insert() allows you to specify the position.
No. List concatenation using + creates a new list, while
append() modifies the existing list.
This usually happens when the return value of append() is
assigned back to the list. Since append() returns
None, code such as
numbers = numbers.append(4) replaces the list with
None.
Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.
Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.
Home Tutorial Online Live Trainings Contact Us © 2026 All rights reserved by www.PythonTutor.net