Easy way to Merge Two Lists In Python

In this tutorial, you will learn the way can easily merge two lists in Python.

Merge Two Lists In Python

You can merge two lists by using the + operator or you can also use the extend() method.

>>> a = [24, 57, 'Python']
>>> b = [45, 2, 'Java']
>>> a += b # a = a + b
>>> print(a)
[24, 57, 'Python', 45, 2, 'Java']
>>>

The extend method doesn’t return any value, it just updates the existing list.

>>> a = [24, 57, 'Python']
>>> b = [45, 2, 'Java']
>>> a.extend(b)
>>> print(a)
[24, 57, 'Python', 45, 2, 'Java']
>>>

Leave a Reply

Your email address will not be published. Required fields are marked *