How to Concatenate Two Lists in Python?

Spread the love

Problem –

You want to concatenate two lists in python.

Solution –

To concatenate two lists in python, you can use the + operator.


In [1]: lst1 = [1, 2, 3]

In [2]: lst2 = [4, 5, 6]

In [3]: lst = lst1 + lst2

In [4]: lst
Out[4]: [1, 2, 3, 4, 5, 6]

Or you can use the extend list method.

In [5]: lst1 = [1, 2, 3]

In [6]: lst2 = [4, 5, 6]

In [7]: lst1.extend(lst2)

In [8]: lst1
Out[8]: [1, 2, 3, 4, 5, 6]

Rating: 1 out of 5.

Leave a Reply