What is the difference between .append() and .extend() in a few words in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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

Python list changes

19th Oct 2021, 7:12 PM
Pius Motai
Pius Motai - avatar
3 Answers
+ 2
Append is for a single value, extend for iterables.
19th Oct 2021, 7:16 PM
Simon Sauter
Simon Sauter - avatar
+ 8
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
20th Oct 2021, 3:50 AM
Vaibhav
Vaibhav - avatar
+ 2
# You can see the difference in an example like this: x = [0] x.append([1, 2]) x.extend([3, 4]) print(x)
19th Oct 2021, 8:07 PM
Lisa
Lisa - avatar