给出数组。我们的任务是将数组转换为普通列表。我们借助tolist()方法解决了这个问题。此函数以(可能是嵌套的)列表形式返回数组。
Step 1: Given an array. Step 2: convert the array to a list using tolist() function. Step 3: Display list
#Python program to convert an array to an ordinary
#list with the same items
from array import *
def arraytolist(A):
lst = A.tolist() # list
print("The List Is ::>",lst)
# Driver code
A= array('i', [20,30,60]) # array
arraytolist(A)输出结果
The List Is ::> [20, 30, 60] The List Is ::> [20, 30, 60]