How to Add Element to a List in Python?

By Hardik Savani October 30, 2023 Category : Python

In this post, we will learn how to add element to list in python. you can see python list add element. This article will give you simple example of how to add elements in list in python. In this article, we will implement a python insert list into list at index.

There are many ways to insert elements to a list in python. i will give you two examples using append() and insert() method to add element at index. 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 = ["One", "Two", "Three"]
  
# Adding new Element to List
myList.append("Four")
  
print(myList)

Output:

['One', 'Two', 'Three', 'Four']

Example 2:

main.py

myList = ["One", "Two", "Three"]
  
# Adding new Element to List
myList.insert(1, "Four")
  
print(myList)

Output:

['One', 'Four', 'Two', 'Three']

I hope it can help you...

Tags :
Shares