Home >Backend Development >Python Tutorial >How to merge two lists in python?

How to merge two lists in python?

烟雨青岚
烟雨青岚Original
2020-06-28 15:54:253833browse

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?

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

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

How to merge two lists in python?

The second method can be done through python’s extend method to complete the list addition

How to merge two lists in python?

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]

How to merge two lists in python?

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!

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