Difference between append vs. extend list methods in Python

0 votes

What's the difference between the list methods append() and extend()?

Aug 8, 2018 in Python by Priyaj
• 57,530 points
287 views

1 answer to this question.

0 votes

append: Appends object at the end.

x = [1, 2, 3] x.append([4, 5]) print (x)

gives you: [1, 2, 3, [4, 5]]


extend: Extends list by appending elements from the iterable.

x = [1, 2, 3] x.extend([4, 5]) print (x)

gives you: [1, 2, 3, 4, 5]

answered Aug 8, 2018 by bug_seeker
• 15,390 points

Related Questions In Python

+1 vote
2 answers

Difference between append vs. extend list methods in Python

Python append() method adds an element to ...READ MORE

answered Aug 21, 2019 in Python by germyrinn
• 180 points
1,470 views
0 votes
2 answers

In Python, what is difference between Array and List?

Lists and arrays are used in Python ...READ MORE

answered Mar 15, 2019 in Python by Taj
• 1,060 points

edited Mar 18, 2019 by Omkar 37,240 views
0 votes
2 answers
0 votes
1 answer

Difference between two lists in python

difference = list(set(list1) - set(list2)) READ MORE

answered May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,036 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 771 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

Create an empty list in python with certain size

Try this instead: lst = [None] * 10 The ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,390 points
5,230 views
0 votes
1 answer

When to use %r instead of %s in Python? [duplicate]

The %s specifier converts the object using ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,390 points
110 views