An array
in python is used to store multiple values or elements of the same datatype in a single variable.
The extend()
function is simply used to attach an item from iterable to the end of the array. In a simpler term, this method is used to add an array of values to the end of a given or existing array.
array.extend(iterable)
The extend()
function takes an array as its parameter value.
# importing the array moduleimport array as arr# creating an integer data type arrayx = arr.array('i', [1,2,3,4,5,6,7])# using the extend function to add an array to the existing arrayx.extend([8,9,10])# printing the new arrayprint(x)
array.array()
function to create an integer type of array.extend()
method to add an array with elements 8
, 9
, and 10
to the original array.