Skip to content
Home / Fundamentals

What is the difference between append and extend

Remember Me
  • use append() to add one single item at the end of your list
  • use extend() to append the items of the specified iterable list to your list


my_list.append(my_object) adds my_object at the end of my_list. my_list.extend(another_list) extends my_list by adding the items of another_list to my_list.

A common mistake is accidentally using append instead of extend which is still valid Python code

# append another list
my_list = [1,2,3]

[1,2,3, [4,5]]

Use Case Examples

# filter out values larger than the threshold value
def filter_out(values: List[int], threshold_value: int) -> List[int]:
    filtered_out_values = []
    for value in values:
        if value >= threshold_value:
    return filtered_out_values

>>> print(filter_out([50,20,40,10,60,55], 30))
"""Collect all car brands from the different countries. Assume that the followings are defined
        list of country names
        function to get the brands of the specific country
        function to filter out brands based on category
car_brands = []
for country in countries:
    brands_from_country = request_brands(country)
    country_car_brands = filter_brands_out(brands_from_country, filter_category="car")