Python List Add Element at Beginning Example

By Hardik Savani October 30, 2023 Category : Python

Hey Artisan,

This detailed guide will cover python list add element at beginning. if you want to see an example of python list add element at first then you are in the right place. This example will help you python add element to list beginning. This post will give you a simple example of how to add an element to the beginning of a list in python. you will do the following things for how to add an element to the start of a list in python.

There are many ways to add elements at the first of the list in python. i will give you two examples using insert() method and list key to add element to list python at index 0. 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 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]

I hope it can help you...

Tags :
Shares