Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
871 views
in Programming by 1 1 3
edited by

In Python, I have two lists 

List1 = [1, 2]
List2 = [3, 4] 

How can I concatenate two lists in Python to get the below result!

List3 = [1, 2, 3, 4]

 


1 Answer

0 like 0 dislike
by 2 3 13
selected by
 
Best answer

You have two options to perform merge or concatenate for two lists in Python:

  1. Simply, you can use "+" operator.

     list3=list1+list2 
     #the result is list3=[1, 2, 3, 4]
    
  2. If you don't need to preserve the first list you can use "extend".

     list1.extend(list2)
    

Hope it helps!

If you don’t ask, the answer is always NO!
...