How to append an array in Python

Overview

An array in Python is used to store multiple values of the same type in a single variable.

The word “append” means “to attach to,” which gives us a clue as to what this shot is all about. To attach an item or value to an existing array, we use the append() function, which appends a new item with a value to the end of the array.

append(x)

Where x is the value that we are attaching to the existing variable.

Parameter value

The append() function takes the value to which we want to add or attach an argument.

Return value

The append() function returns an array containing the new value added to the end of the array.

Example

# importing the array module
import array as arr
# creating an integer data type array
x = arr.array('i', [1,2,3,4,5,6,7])
# using the append function
x.append(100)
# printing the new array
print(x)
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources