Add Element at the End of List in Python

Dec 01, 2022

.

Admin

Add Element at the End of List in Python

Hi Dev,

This article is focused on add element at the end of list in python. This tutorial will give you simple example of how to insert element at the end of list in python. This post will give you simple example of how to add item to end of list python. This tutorial will give you simple example of how to add element at the end of list in python. follow bellow step for python list add last element.

There are many ways to add elements at end of the list in python. i will give you two examples using append() method and insert() method to insert element at end in python list. so let's see the below examples.

so let's see following examples with output:

Example 1:


main.py

myList = [1, 2, 3, 4]

# Add new element at end

myList.append("Last Elem")

print(myList)

Output:

[1, 2, 3, 4, 'Last Elem']

Example 2:

main.py

myList = [1, 2, 3, 4]

# Add new element at end

myList.insert(len(myList), "Last Elem")

print(myList)

Output:

[1, 2, 3, 4, 'Last Elem']

#Python