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
39 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, 2019 in Python by Junaid
124 views
0 votes
2 answers
0 votes
1 answer

Write code to create a list of word lengths for the words in original_str using the accumulation pattern and assign the answer to a variable num_words_list.

Hi,  num_words_list = len(original_str.split()) original_str.split() - split words in ...READ MORE

answered May 27 in Python by Niroj
• 43,540 points
627 views
+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
• 200 points
10,949 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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,188 views
0 votes
0 answers
+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
22,717 views
+1 vote
7 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
8,310 views