What is the difference between Python's list methods append and extend?

In Python, lists have several methods for adding elements. Two commonly used methods are append and extend. Although they both add elements to a list, they operate differently. Understanding these differences is crucial for manipulating lists effectively.

append

The append method adds a single element to the end of the list. This element can be of any data type (another list, a number, a string, etc.).

Syntax:

list.append(element)

Example:

my_list = [1, 2, 3] my_list.append(4) print(my_list) # Output: [1, 2, 3, 4] # Appending a list my_list.append([5, 6]) print(my_list) # Output: [1, 2, 3, 4, [5, 6]]

extend

The extend method adds elements from an iterable (such as another list, a tuple, a set, etc.) to the end of the list. Unlike append, extend iterates over its argument and adds each element to the list.

Syntax:

list.extend(iterable)

Example:

my_list = [1, 2, 3] my_list.extend([4, 5, 6]) print(my_list) # Output: [1, 2, 3, 4, 5, 6] # Extending with a string (iterable of characters) my_list.extend('abc') print(my_list) # Output: [1, 2, 3, 4, 5, 6, 'a', 'b', 'c']

Key Differences

  1. Functionality:

    • append adds its argument as a single element to the end of the list. The length of the list increases by one.
    • extend iterates over its argument, adding each element to the list. The length of the list increases by however many elements were in the iterable.
  2. Type of Argument:

    • append can take any type of object as its argument.
    • extend requires an iterable (list, tuple, string, etc.) as its argument.
  3. Resulting Structure:

    • append can result in a nested list if a list is appended.
    • extend always flattens the iterable into the list.

Example Comparison

Let's compare append and extend with an example to highlight their differences:

my_list = [1, 2, 3] # Using append my_list.append([4, 5]) print(my_list) # Output: [1, 2, 3, [4, 5]] # Resetting the list my_list = [1, 2, 3] # Using extend my_list.extend([4, 5]) print(my_list) # Output: [1, 2, 3, 4, 5]

Summary

  • append:

    • Adds its argument as a single element to the end of the list.
    • Increases the list's length by one.
    • Argument can be any type of object.
  • extend:

    • Iterates over its argument, adding each element to the list.
    • Increases the list's length by the number of elements in the iterable.
    • Requires an iterable (list, tuple, string, etc.) as its argument.

Understanding these differences helps in choosing the right method for adding elements to a list based on the desired outcome. For more detailed tutorials and practical examples on Python and other programming concepts, consider exploring Grokking Python Fundamentals or Grokking the Coding Interview on DesignGurus.io, which provides comprehensive courses on essential coding and interview techniques.

TAGS
Coding Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What is ReactJS basics?
What is an aptitude test in software engineering?
What is a passing score for CCNA?
What is IP and router?
Why work at PayPal interview question?
What is a technology assessment test?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.8
(1,192 learners)
Discounted price for Your Region

$123

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.