Skip to main content

How to Join Two Lists in Python with the + Operator

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

To put two lists end to end in Python, add them with +: first + second is a new list with the items of first followed by those of second. Neither list changes. This guide joins a list of fruits and a list of vegetables on Python 3.15.2.

Syntax​

Syntax
<new list> = <first list> + <second list>
PartWhat it means
<first list>The list whose items come first
<second list>The list whose items follow. It has to be a list too
<new list>The result: a new list. Both lists you added stay as they were

The built-in types documentation lists s + t as "the concatenation of s and t", and the tutorial says "Lists also support operations like concatenation".

The Example​

The script joins ["apple", "banana"] and ["carrot", "pea"] into a list called basket, prints it, and prints the first list again to show it didn't change.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

join_lists.py
fruits = ["apple", "banana"]
vegetables = ["carrot", "pea"]

basket = fruits + vegetables

print(basket)
print(fruits)

The join_lists.py script in a macOS-style code window: a fruits list and a vegetables list, joined with basket = fruits + vegetables, then print of basket and fruits.

  • fruits + vegetables builds a new list from the items of both.
  • basket holds that new list.
  • print(fruits) checks the first list afterwards.

Step 2: Run It​

Terminal
uv run python join_lists.py
Output
['apple', 'banana', 'carrot', 'pea']
['apple', 'banana']

The terminal after uv run python join_lists.py: the joined list apple, banana, carrot, pea, then the unchanged fruits list apple, banana.

basket has all four items in order, and fruits still has its two: + made a new list. The command works unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Adding a single item: fruits + "carrot"TypeError: can only concatenate list (not "str") to listPut the item in a list: fruits + ["carrot"]
Using append() to join: fruits.append(vegetables)The second list goes in as one item: ['apple', 'banana', ['carrot', 'pea']]Use +, or extend() to change the first list
Expecting + to change the first listfruits stays the same; only the new list has everythingKeep the result: basket = fruits + vegetables

Troubleshooting​

SymptomLikely causeFix
TypeError: can only concatenate list (not "...") to listOne side isn't a listWrap the item in [...], or convert the other side with list(...)
A list inside your listappend() added the whole second list as one itemUse + or extend()

FAQ​

What's the difference between + and extend()?​

+ makes a new list and leaves both lists alone. fruits.extend(vegetables) adds the items to fruits itself, which then prints ['apple', 'banana', 'carrot', 'pea'].

Is there another way to write it?​

Unpacking: [*fruits, *vegetables] also gives ['apple', 'banana', 'carrot', 'pea'], and it can join more than two lists or mix in single items.

Conclusion​

fruits + vegetables returned a new list with all four items and left fruits as it was. Both sides of + have to be lists; to change a list in place, use extend().

Additional Resources​