Python Add Element to a List Example

Published On: 02/12/2022 | Category: Python


Hi Guys,

Here, I will show you how to add element to list in python. step by step explain how to add elements in list in python. We will look at example of python insert list into list at index. you can see python add list to list at index.

In Python, there are numerous methods for adding elements to a list. I'll show you two examples of adding elements at index using the append() and insert() methods. So, take a look at the examples below.

So let's see bellow example:

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']

It will help you....

Happy Pythonic Coding!