Assignment
Q1. Differentiate between
a) List and String
b) append and extend
c) pop and del
d) pop and remove
Q2. Write a program to search an element in a list.
Q3. Write a program to find the maximum element in the list.
Q4. Write a program to count the frequency of given element in the list.
Q5. Write the most appropriate method to perform the given task?
a) Delete a given element from the list
b) Delete 4th element from the list
c) Add an element in the end of the list
d) Add an element in the beginning of the list
e) Add an element of a list in the end of the list
Ans: (a) remove (b)pop() (c) append() (d) insert (e) insert() (f) extend()
Q6. Predict the output:
List1=[‘c’,’o’,’m’,’p’,’u’,’t’,’e’,’r’]
List1[3:4] = [ ]
print(List1)
List1[2:6] = [ ]
Print(List1)
Ans:
['c', 'o', 'm', 'u', 't', 'e', 'r']
['c', 'o', 'r']
Q7. Predict the output:
List1=[12,36,98,65,36,53,71]
print([Link](98))
print([Link](98))
[Link]([Link](36))
print(List1)
Ans:
2
1
[12, 36, 98, 65, 36, 53, 71, 2]
Q8. Predict the output:
List1=[1,2,3]
List2=[33,44,55,66,77,88,99]
List3=List1+List2
>>>List*3
>>>List3
>>>List1+List2
>>>List3[3:9:2]
>>>List3[ : : 3]
>>>List3[0:10:3]
>>>List3[2 : : 2]
Ans:
[1, 2, 3, 1, 2, 3, 1, 2, 3]
[1, 2, 3, 33, 44, 55, 66, 77, 88, 99]
[33, 55, 77]
[1, 33, 66, 99]
[1, 33, 66, 99]
[3, 44, 66, 88]