Python append List Function

Python append List is used to add an item to the end of an old list. This Python append list function help us to add given item (New_item) at the end of the existing Old_list The syntax of this append function is as shown below

list.append(New_item)

Python List append Function Example

First, we declared an integer list with four integer values. Next, the append code adds 50 to the end of List a

TIP: Please refer to the List and List 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 an integer list using this list append 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 append example, we declared a string list. Next, we used the list append function to add another fruit to this list.

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 list append example. However, we are allowing the user to enter the length of a List. Next, we used For Loop to append those numbers to the list.

intList = []
 
number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, number + 1):
    value = int(input("Please enter the Value of %d Element : " %i))
    intList.append(value)
    
item = int(input("Please enter the New Item to append : " ))
print("Original List Items are : ", intList)
intList.append(item)
print("New List Items are      : ", intList)
Python Append List Items 4

In this program, we used the list append method to add words.

strFruits = []
 
number = int(input("Please enter the Total Number of Elements: "))
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 of Elements: 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']