How to join two lists in Python (Join Multiple Lists)

You can join two lists in Python with different methods. We will discuss two easy methods to join lists. If you want to learn Python then I will highly recommend you to read This Book.

How to join two lists in Python (Join Multiple Lists)
How to join two lists in Python (Join Multiple Lists)

Method 1: Join two lists with Extend Method

Extend Method is used to join two lists in Python. In the given example, ‘a’ and ‘b’ are two variables in which lists are store. The following code will extend the ‘list a’ and the elements of ‘b’ will be added in ‘list a’.

a = [1,2,3,4,5,6,7,8,9,10]
b = [11,12,13]
a.extend(b)
print(a)

Method 2: Join two lists with Addition Simply

In this method, simply add two lists with add symbol. I will join two lists and save it in new variable ‘c’.

a = [1,2,3,4,5,6,7,8,9,10]
b = [11,12,13]
c = a+b
print(c)

Join Multiple Lists

You can also join multiple lists and also combine strings and integers in one list. The following example will join multiple lists and also combine strings and integers.

a = [10,9,7,5,2,3,21]
b = [31,42,45]
c = ["AiHints",'Artificial Intelligence']
d = [1.23, 49.3, 56.2, 70, 'AI']
e = a+b+c+d
print(e)

People are also reading:

What is Computer Vision? Examples, Applications, Techniques

Top 10 Python Books | Best Python Books

Top 10 Computer Vision Books

Leave a Comment

Your email address will not be published.