Concatenating the two lists in Python

Concatenating the two lists in Python

In this post we will give you information about Concatenating the two lists in Python. Hear we will give you detail about Concatenating the two lists in PythonAnd how to use it also give you demo for it if it is necessary.

we are going to learn how to concatenate the two lists in Python with the help of examples.

Concatenation means the joining of two lists into a single list.

Using + plus operator

To concatenate the two lists into a single list, we can use the + operator in Python.

Here is an example:

list1 = [1, 2, 3]list2 = [4, 5, 6]result = list1 + list2 # joining two listsprint(result)

Output:

[1, 2, 3, 4, 5, 6]

Using the extend() method

We can also use the built-in extend() method in python, to join a list 2 to the end of list 1.

Here is an example:

list1 = [1, 2, 3]list2 = [4, 5, 6]list1.extend(list2) # joining two listsprint(result)

Output:

[1, 2, 3, 4, 5, 6]

Or we can use the * unpacking operator in Python.

list1 = [1, 2, 3]list2 = [4, 5, 6]result = [*list1, *list2] # joining two listsprint(result)

The * unpacking operator unpacks the iterables (such as lists, tuples etc) into a individual elements.

Hope this code and post will helped you for implement Concatenating the two lists in Python. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US