Enlarging a list using functions using append() and extend()

0 votes
What is the difference between append() and extend()?
Jun 1, 2018 in Python by kaalabilli
• 1,090 points
15 views

1 answer to this question.

0 votes

Let me illustrate this with an example - 

l = [1, 2, 3, 4, 5]
>>> l
[1, 2, 3, 4, 5]
>>> e = [6, 7]
>>> l.append(e)
>>> l
[1, 2, 3, 4, 5, [6, 7]]
>>> l = [1, 2, 3, 4, 5]
>>> e = [6, 7]
>>> l.extend(e)
>>> l
[1, 2, 3, 4, 5, 6, 7]
answered Jun 1, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
1 answer

Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...READ MORE

answered May 14 in Python by Junaid
34 views
0 votes
1 answer
+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 in Python by germyrinn
• 180 points
190 views
0 votes
0 answers

Storing a list of arrays into a CSV file and retrieving it back in a different program

This is the code that I am ...READ MORE

Jun 6, 2018 in Python by ariaholic
• 7,340 points
40 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 216 views
+4 votes
6 answers
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
4,861 views
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
588 views