What is the difference between .append() and .extend() in a few words in Python? | Sololearn: Learn to code for FREE!

+1

What is the difference between .append() and .extend() in a few words in Python?

Python list changes

10/19/2021 7:12:32 PM

Pius Motai

3 Answers

New Answer

+2

Append is for a single value, extend for iterables.

+6

Append: Adds its argument as a single element to the end of a list. Extend(): Iterates over its argument and adding each element to the list and extending the list

+2

# You can see the difference in an example like this: x = [0] x.append([1, 2]) x.extend([3, 4]) print(x)