.append() appends a single object at the end of the list:
>>> x = [1, 2, 3]
>>> x.append([4, 5])
>>> print(x)
[1, 2, 3, [4, 5]]
.extend() appends multiple objects that are taken from inside the specified iterable:
>>> x = [1, 2, 3]
>>> x.extend([4, 5])
>>> print(x)
[1, 2, 3, 4, 5]
Answer from kender on Stack OverflowReddit
reddit.com โบ r/learnpython โบ append() vs. extend()
r/learnpython on Reddit: append() vs. extend()
July 22, 2023 -
Can someone please explain the difference between the append and extend functions in Python really quickly? Is it just that extend can add multiple items simultaneously, whereas append can only add one at a time? Can you also please include an example if you have the time?
Top answer 1 of 2
16
Append takes an item and inserts it as an item to the list. Extend takes a LIST, and inserts each item in the given list as items. a=[1,2,3] a.extend([4]) # will result in [1,2,3,4] a.append([4]) # will result in [1,2,3,[4]] The last item being a list containing 4, and not just 4.
2 of 2
1
Hey mate! In short, the method extend() requires an iterable argument.
Is it possible to add items to a list without using something like the .append function Nov 20, 2023
r/learnpython 2y ago
Top answer 1 of 16
5931
.append() appends a single object at the end of the list:
>>> x = [1, 2, 3]
>>> x.append([4, 5])
>>> print(x)
[1, 2, 3, [4, 5]]
.extend() appends multiple objects that are taken from inside the specified iterable:
>>> x = [1, 2, 3]
>>> x.extend([4, 5])
>>> print(x)
[1, 2, 3, 4, 5]
2 of 16
743
.append() adds an element to a list,
whereas .extend() concatenates the first list with another list/iterable.
>>> xs = ['A', 'B']
>>> xs
['A', 'B']
>>> xs.append("D")
>>> xs
['A', 'B', 'D']
>>> xs.append(["E", "F"])
>>> xs
['A', 'B', 'D', ['E', 'F']]
>>> xs.insert(2, "C")
>>> xs
['A', 'B', 'C', 'D', ['E', 'F']]
>>> xs.extend(["G", "H"])
>>> xs
['A', 'B', 'C', 'D', ['E', 'F'], 'G', 'H']
Lists in Python: .append() v. .insert()
What you just said - append appends elements to the end, insert inserts them in an arbitrary position. More on reddit.com
append() vs. extend()
Append takes an item and inserts it as an item to the list. Extend takes a LIST, and inserts each item in the given list as items. a=[1,2,3] a.extend([4]) # will result in [1,2,3,4] a.append([4]) # will result in [1,2,3,[4]] The last item being a list containing 4, and not just 4. More on reddit.com
Equivalent of dictionary.update() but for appending when value is a collection?
There is not an exact equivalent, but there are things that are similar. I would suggest using a default dict: import collections d = collections.defaultdict(list) d[5].append(4) But if it had to be a standard dictionary, you could do d[ind] = d.get(ind, []) + [x] Note: the second will not modify existing lists in place, which may or may not be a problem. EDIT: Per u/commy2 's reply below, setdefault is better way if you're restricted to regular dictionaries - especially if your lists will be getting long so that copying them is nontrivial, or if it's important to modify the lists in place. More on reddit.com
How do I concatenate two lists in Python?
Use the + operator. More on reddit.com
Videos
00:48
Extend Vs Append Python Lists #python #code #programming - YouTube
07:29
Append OR Extend - How to Use Them Correctly in Python ๐ - YouTube
08:08
"append" VS "extend" in Python - YouTube
Python append vs extend โ What's the Real Difference? #shorts
07:12
Simple Python | Append, Extend & Insert explained - YouTube
Naukri
naukri.com โบ code360 โบ library โบ difference-between-append-and-extend-in-python
Difference Between Append and Extend in Python
August 11, 2025 - Almost there... just a few more seconds
freeCodeCamp
freecodecamp.org โบ news โบ python-list-append-vs-python-list-extend
Python List Append VS Python List Extend โ The Difference Explained with Array Method Examples
March 22, 2020 - The name of the method extend. (Now things start to change...). Within parentheses, an iterable (list, tuple, dictionary, set, or string) that contains the items that will be added as individual elements of the list. ๐ก Tips: According to the Python documentation, an iterable is defined as "an object capable of returning its members one at a time".
Wyzant
wyzant.com โบ resources โบ ask an expert
Difference between append vs. extend list methods in Python? | Wyzant Ask An Expert
May 11, 2019 - append() adds its argument as a single element to the end of the list. If you append a list, the entire list becomes one element. extend() takes an iterable and adds each item from it individually to the list.
Scaler
scaler.com โบ home โบ topics โบ difference between append and extend in python list methods
Difference Between Append and Extend in Python List Methods | Scaler Topics
April 4, 2024 - The append() method in the Python programming language adds an item to a list that already exists whereas the extend() method adds each of the iterable elements which is supplied as a parameter to the end of the original list.
freeCodeCamp
freecodecamp.org โบ news โบ python-list-methods-append-vs-extend
Python List Methods โ append( ) vs extend( ) in Python Explained with Code Examples
June 21, 2021 - So if you extend a list of length len1 with a list of length len2 , the length of the list on which the extend() method is called is len1 + len2. What if we wish to add a single item and not the entire list (or any iterable) to our existing list? In the following example, let's add the boolean value True to list_1 using append()as shown below.