Appending List to List in Python : 3 Best Examples

Appending List to List in Python

Do you want to append list to list in Python ? If yes then you have come at the right place. In this post you will know how to append list to list in python using various examples.

What is a List?

It’s obvious that you must know what is a list. But to those who do not know, the list is a data structure that allows you to store multiple values in a single variable. The list is widely used by most of the coders. It allows you to manipulate the variable inside the list.

How to perform Appending List to List in Python

Now let’s know the various examples for appending a list to a list in Python. Just follow it for a deep understanding.

Example 1: Append list to existing list

Suppose you want to append a new list to the existing list. Then you have to use the append() function. Here you will just pass the new list to the existing list as an argument.

Use the below lines of code to achieve it.

list1 = ["A","B","C"]
list2= ["D","E","F","G"]
list1.append(list2)
print(list1)

Output

Appending list to list using the append() function
Appending list to list using the append() function

 

Example 2: Appending elements to the list

The above example completely appends the list to another list. But if you want to append only elements to the existing list then you will use the extend() function. It takes a list as an argument.

Run the below lines of code to achieve that.

list1 = ["A","B","C"]
list2= ["D","E","F","G"]
list1.extend(list2)
print(list1)

Output

Appending list elemets to list using the extend function
Appending list elements to list using the extend function

 

Example 3: Using the + Operator

The third example to append a list to a list is the use of the + operator. The process is the same as an addition but instead of a particular number it will add the elements to the existing list.

Execute the below lines of code and see the output.

list1 = ["A","B","C"]
list2= ["D","E","F","G"]
final_list = list1+list2
print(final_list)

Output

Appending list elemets to list using the pluse operator

Conclusion

In this tutorial, you have learned how to append a list to a list in Python. You have also learned how to append all the elements to the existing list using the extend() function, plus operator and other approaches.

I hope you have liked this tutorial. If you have any query then you can contact us for more information.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner