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
32 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
82 views
0 votes
1 answer

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 2,980 points
1,681 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
• 180 points
1,366 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 aryya
• 7,350 points
85 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 750 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
15,328 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
4,675 views