Python Add Element at the Beginning of List Example

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


Hi Guys,

Are you looking for example of python list add element at first. I’m going to show you about python add element to list beginning. I would like to show you how to add an element to the beginning of a list in python. we will help you to give example of how to add an element to the start of a list in python.

In Python, there are numerous ways to add elements to the beginning of a list. I'll show you two examples of inserting elements at the end of a Python list using the insert() methods and list key. So, take a look at the examples below.

So let's see bellow example:

Example 1:

main.py
myList = [1, 2, 3, 4]
  
# Add new element at first
myList.insert(0, "First Elem")
  
print(myList)
Output
['First Elem', 1, 2, 3, 4]

Example 2:

main.py
myList = [1, 2, 3, 4]
  
# Add new element at firdt
myList = ["First Elem"] + myList
  
print(myList)
Output
['First Elem', 1, 2, 3, 4]

It will help you....

Happy Pythonic Coding!