Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

array
function
python
communitycreator

How to append an array in Python

Onyejiaku Theophilus Chidalu

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)

RELATED TAGS

array
function
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring