Home > Article > Backend Development > How to merge two lists in python?
How to merge two lists in python: 1. You can use the addition method to merge lists, for example "c = a b"; 2. You can merge lists through python's extend method, for example "a.extend(b )".
How to merge two lists in Python:
First open the code editor and enter the code compilation environment
The first method uses the addition method to implement list addition
a = [1,2,3]
b = [4,5,6]
c = a b
Using the compiler to execute the result c is [1,2,3,4,5,6]
The second method can be done through python’s extend method to complete the list addition
Enter code
a = [1,2,3]
b = [4,5,6]
a.extend(b)
Compile and execute The result of a is [1,2,3,4,5,6]
Recommended tutorial: "python tutorial"
The above is the detailed content of How to merge two lists in python?. For more information, please follow other related articles on the PHP Chinese website!