Practical 1
Practical 1
Q1: Create Arrays of different data types in python using array module
#integer array
a=arr.array('i',[3,5,8,1,9])
print('a: ',a)
for i in range(len(a)):
print(a[i])
#double array
b=arr.array('d',l2)
print('\nb: ',b)
#traversing
for x in b:
print(x)
#character/Unicode array
c=arr.array('u',"Hello")
print("\nc: ",c)
#traversing
for x in c:
print(x,end=' ')
Output
5
8
1.5
3.7
9.8
c: array('u', 'Hello')
Hello
#Practical 1: Array/List
#integer array
a=arr.array('i',[3,5,8,1,9])
print('a: ',a)
for i in range(len(a)):
print(a[i])
a.append(90)
a.remove(8) #remove method can be used to remove particular element from array
a.pop()
#Search
#index(ele) method can be used to search the given ele if it is present then it will return the index or
it will generate error
Output:
9
Element at index 2 is: 8