List As Array
List As Array
Array:
Syntax :
import array
example:
a=array.array(‘i’,[1,2,3,4])
a- array name
array- module name
i- integer datatype
Example
Program to find sum of array elements
import array
sum=0
a=array.array('i',[1,2,3,4])
for i in a:
sum=sum+i
print(sum)
Output
10
fromlist() function is used to append list to array. Here the list is act like a
array.
Syntax:
arrayname.fromlist(list_name)
Example
Output
35
Methods in array
a=[2,3,4,5]