How to Add Multiple Elements to a List in Python?

By Hardik Savani October 30, 2023 Category : Python

Hello,

This article will give you an example of how to add multiple elements to a list in python. let’s discuss how to insert multiple elements in list in python. you can understand the concept of python list add multiple elements. This tutorial will give you a simple example of python list insert multiple elements. Let's see below example python add items of list to list.

There are many ways to add multiple items to a python list. i will give you three examples using extend() method, append() method and concat to insert multiple elements to python list. so let's see the below examples.

You can use these examples with python3 (Python 3) version.

let's see below a simple example with output:

Example 1:

main.py

myList = [1, 2, 3, 4]
  
# Add new multiple elements to list
myList.extend([5, 6, 7])
  
print(myList)

Output:

[1, 2, 3, 4, 5, 6, 7]

Example 2:

main.py

myList = [1, 2, 3, 4]
   
# Add new multiple elements to list
myList.append(5)
myList.append(6)
myList.append(7)
  
print(myList)

Output:

[1, 2, 3, 4, 5, 6, 7]

Example 3:

main.py

myList = [1, 2, 3, 4]
myList2 = [5, 6, 7]
 
# Add new multiple elements to list
newList = myList + myList2
  
print(newList)

Output:

[1, 2, 3, 4, 5, 6, 7]

I hope it can help you...

Tags :
Shares