Now Here we are going to discuss more How can I concatenate two lists in Python? There are two ways to do so first can be we can simply add both the list using + (Plus Operator) where we can simply add them as two strings, and we can also use the inbuild function extend to concatenate two Lists
Concatenate Using ‘+’ Operator
We can simply concatenate two lists by using ‘+’ as adding at the end of the first list we make the concatenate and we can use both the list as one and save them in a single variable which simply means we can reduce the number os variables if we need.
Concatenation is a way to reduce the number of variables and make a single and master list where we can store all the elements of both list, In this way we can keep on concatenating a number of lists and store all the elements in a single line. that can help in accessing elements easily and simply.
listone = [1, 2, 3] listtwo = [4, 5, 6] joinedlist = listone + listtwo
Here is an example explaining how we can use the + operator to concatenate two lists and get the output as [1, 2,3, 4, 5, 6] which is nothing but simply the addition of both the list’s elements in a single list.
Concatenate Usind In Build Functions
There are differences in build functions that can concatenate two strings simply by passing the lists as parameters. So let’s discuss the ways to do so.
append is an inbuild function that is used to concatenate two strings of lists so we can do so using append by simply passing a list as an argument and it will add both the list and concatenate. Follow the example for a better understanding:
listone = [1,2,3] listtwo = [4,5,6] listone.append(listtwo)
Here this program will also result as [1, 2,3, 4, 5, 6] as it will also add all the elements of listtwo at the end of listone and we get over desired output.
extend also concatenate as append does with the same property except we can add the list at any location of out choice but in case of concatenate we need to add the second list at the end of the first list only so here is an example for the same:
listone = [1,2,3] listtwo = [4,5,6] listone.extend(listtwo)
As we have seen in previous examples it will also give the same example where the elements of the second list are concatenated at the end of list one.
Learn More About Concatenate two List at: https://stackoverflow.com/questions/1720421/how-do-i-concatenate-two-lists-in-python
And also visit at for more information: Python List Examples – How to Concatenate Two or more Lists in Python