ItSolutionStuff.com

How to Add Element to a List in Python?

By Hardik Savani • October 30, 2023
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: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Python List Print All Elements Except First Example

Read Now →

Python List Print All Elements Except Last Example

Read Now →

How to Get Min Value from Python List?

Read Now →

How to Convert List to Capitalize First Letter in Python?

Read Now →

How to Get Max Value from Python List?

Read Now →

How to Convert List to Uppercase in Python?

Read Now →

Python Convert List into String with Commas Example

Read Now →

Python Get Second Last Element of List Example

Read Now →

Python Delete Files Matching Pattern Example

Read Now →

Python Post Request with Basic Authentication Example

Read Now →

How to Check if Today is Saturday or not in Python?

Read Now →