Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. append vs extend

Python · Collections & Basics

append vs extend

Easypython-05
listappendextendmutable

Question

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

Solution

Both grow a list in place, but they treat the argument differently.

append(x)

  • Adds x as a single element at the end.
  • Length increases by 1.

extend(iterable)

  • Iterates over iterable and adds each item.
  • Length increases by the number of items yielded.
a = [1, 2]
a.append([3, 4])
print(a)          # [1, 2, [3, 4]]  ← nested list

b = [1, 2]
b.extend([3, 4])
print(b)          # [1, 2, 3, 4]    ← flattened addition

c = [1, 2]
c.extend("ab")
print(c)          # [1, 2, 'a', 'b']  strings are iterable

# + creates a new list; append/extend mutate
d = [1, 2] + [3, 4]   # new object

Interview tip: If someone says "append multiple values," clarify whether they mean one nested object (append) or many elements (extend / +=).

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext