Python append List Function

The append List is used to add an item to the end of an old one. This append function helps us to add a given item (New_item) at the end of the existing Old_list, and the syntax of the Python append List Function is as shown below.

list.append(New_item)

Python List append Function Example

First, we declare an integer list with four integer values, and the following code adds 50 to the end of it.

TIP: Please refer to the List and functions articles in Python.

a = [10, 20, 30, 40]

print("Original Items are : ", a)
a.append(50)
print("New Items are       : ", a)
Original Items are :  [10, 20, 30, 40]
New Items are      :  [10, 20, 30, 40, 50]

We are adding three integer values to integer items using this function.

a = [10, 20, 30, 40]

print("Original Items are : ", a)
a.append(50)
a.append(60)
a.append(70)
print("New Items are       : ", a)
Original Items are :  [10, 20, 30, 40]
New Items are      :  [10, 20, 30, 40, 50, 60, 70]

Python append List of Strings example

In this example, we declared a string element. Next, we used this method to add another fruit to this.

Fruits = ['Apple', 'Orange', 'Kiwi', 'Grape']

print("Original Items are : ", Fruits)
Fruits.append('Banana')
print("New Items are       : ", Fruits)
Original Items are :  ['Apple', 'Orange', 'Kiwi', 'Grape']
New Items are      :  ['Apple', 'Orange', 'Kiwi', 'Grape', 'Banana']

This program is the same as the first example. However, we are allowing the user to enter the length of it. Next, we used For Loop to add those numbers to the empty one.

intLi = []
 
number = int(input("Enter the Total Number of Elements: "))
for i in range(1, number + 1):
    value = int(input("Enter the %d Element : " %i))
    intLi.append(value)
    
item = int(input("Enter the New Element : " ))
print("Original Elements are : ", intLi)
intLi.append(item)
print("New Elements are      : ", intLi)
Python append List Items  Example

In this program, we used this method to add words.

strFruits = []
 
number = int(input("Please enter the Total Number : "))
for i in range(1, number + 1):
    value = input("Please enter the Value of %d Element : " %i)
    strFruits.append(value)
    
item = input("Please enter the New Item to append : " )
print("Original Items are : ", strFruits)
strFruits.append(item)
print("New Items are      : ", strFruits)
Please enter the Total Number : 3
Please enter the Value of 1 Element : Apple
Please enter the Value of 2 Element : Banana
Please enter the Value of 3 Element : Orange
Please enter the New Item to append : Kiwi
Original Items are :  ['Apple', 'Banana', 'Orange']
New Items are      :  ['Apple', 'Banana', 'Orange', 'Kiwi']