Home  >  Article  >  Backend Development  >  How to merge two lists in python

How to merge two lists in python

藏色散人
藏色散人Original
2019-07-06 11:18:2222721browse

How to merge two lists in python

How to merge two lists in python?

How to merge two lists in python:

First open the code editor and enter the code compilation environment

How to merge two lists in python

The first method uses the addition method to implement list addition

a = [1,2,3]
b = [4,5,6]
c = a+b

How to merge two lists in python

Use the compiler to execute and the result c is [1,2,3,4,5,6]

How to merge two lists in python

The second method List addition can be completed through the extend method of python

Enter the code

a = [1,2,3]
b = [4,5,6]
a.extend(b)

How to merge two lists in python

Compile and execute, the result of a is [1,2,3,4 ,5,6]

How to merge two lists in python

Related recommendations: "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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn