An array
is a collection of multiple values, items, or elements of the same datatype
in a single variable.
The tolist()
function is used to convert a given array to an ordinary list with the same items, elements, or values.
The syntax of the tolist()
function is given below:
array.tolist()
The tolist()
function does not take any parameters.
The tolist()
function returns a list that contains the same items of the original array.
Let’s see an example.
# 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 tolist() function to change the array to a listy = x.tolist()# Printing the listprint(y)