2. Problem to add elements from list1 to list2.

There are two ways to add elements from list1 to list2, fone is concatenation with the plus operator and the second one is to add elements with extend method with the help of the below-given steps.

Table of Contents

Method 1 : Using concatenation

Add elements:

Steps to solve the program
  1. Take two lists as inputs.
  2. Add them using the ” ” operator.
  3. Print the final list.
				
					#Input lists
list1 = [3, 6, 7, 81, 2]
list2 = [11, 15, 17, 13]

#Adding lists
output = list1 + list2

#Printing output
print(output)

				
			

Output :

				
					[3, 6, 7, 81, 2, 11, 15, 17, 13]

				
			

Method 2 : Using extend()

Steps to solve the program
  1. Take two lists as input.
  2. Combine both lists using extend().
  3. Print the combined list.
				
					#Input lists
list1 = [3, 6, 7, 81, 2]
list2 = [11, 15, 17, 13]

#Extend method
list1.extend(list2)

#Printing output
print(list1)

				
			

Output :

				
					[3, 6, 7, 81, 2, 11, 15, 17, 13]
				
			

Related Articles

Square of each number

Sum of all list elements.

Leave a Comment