Python append List Function

Python append List is used to add an item to the end of an old list. The syntax of this List append function

list.append(New_item)

This Python list append function help us to add given item (New_item) at the end of the Old_list

Python append List Function Example

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

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

# Python Append List Items

a = [10, 20, 30, 40]

print("Original List Items are : ", a)
a.append(50)
print("List Items are          : ", a)

List append function output

Original List Items are :  [10, 20, 30, 40]
List Items are          :  [10, 20, 30, 40, 50]

append List Function Example 2

We are adding three integer values to an integer list using this list append function.

# Python Append List Items

a = [10, 20, 30, 40]

print("Original List Items are : ", a)
a.append(50)
a.append(60)
a.append(70)
print("List Items are          : ", a)

List append function output

Original List Items are :  [10, 20, 30, 40]
List Items are          :  [10, 20, 30, 40, 50, 60, 70]

Python List append on Strings Example 3

In this append example, we declared a string list. Next, we used the list append function to add another fruit to this list.

# Python Append List Items

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

print("Original List Items are : ", Fruits)
Fruits.append('Banana')
print("List Items are          : ", Fruits)

List append function output

Original List Items are :  ['Apple', 'Orange', 'Kiwi', 'Grape']
List Items are          :  ['Apple', 'Orange', 'Kiwi', 'Grape', 'Banana']

List append Function Example 4

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.

# Python Append List Items

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

List append Function Example 5

In this program, we used the list append function to add words to a list

# Python Append List Items

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

List append function output

Please enter the Total Number of List 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 List Items are :  ['Apple', 'Banana', 'Orange']
New List Items are      :  ['Apple', 'Banana', 'Orange', 'Kiwi']