Question

What is the difference between append() and extend()?

Updated on June 2, 2025 | By Learnzy Admin | πŸ‘οΈ Views: 184 students

Solution
βœ” Verified

append():

  • Adds a single item to the end of the list.
  • The item can be of any type (including another list).
  • If you append a list, it adds the whole list as one element (nested list).
  • a = [1, 2, 3]
    a.append([4, 5])
    # Result: [1, 2, 3, [4, 5]]

extend():

  • Adds each element from an iterable (like a list, tuple, etc.) to the end of the list.
  • It "extends" the list by adding elements one by one.
  • If you extend with a list, its items are added individually (not nested).
  • a = [1, 2, 3]
    a.extend([4, 5])
    # Result: [1, 2, 3, 4, 5]
Was this solution helpful? 39
Click here to download practice questions on Python Lists

More Questions on Python Lists

Question 1

How to check if two lists are equal?


View solution
Question 2

Find common elements in two lists


View solution
Question 3

Is Python list mutable?


View solution
Question 4

How to remove duplicates from a list?


View solution
Question 5

Difference between sort() and sorted()?


View solution
Question 6

What is a list in Python?


View solution
Question 7

How to remove an element from a list?


View solution