Mcq's List

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1. Which of the following would give an error?

A. list1=[] C. list1=[2,8,7]
B. list1=[]*3 D. None
2. Which of the following is true regarding lists in Python?
A. Lists are immutable.
B. Size of the lists must be specified before its initialization
C. Elements of lists are stored in contagious memory location.
D. size (list1) command is used to find the size of lists.
3. What will be the output of below Python code?
list1=[8,0,9,5]
print(list1[::-1])
A. [5,9,0,8] B. [8,0,9] C. [8,0,9,5] D. [0,9,5]
4. Which of the following will give output as [23,2,9,75] ?If list1=[6,23,3,2,0,9,8,75]
A. print(list1[1:7:2]) B. print(list1[0:7:2])
C. print(list1[1:8:2]) D. print(list1[0:8:2])
5. The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95].
How can the student’s average mark be calculated?
A. print(avg(list1)) C. print(sum(list1)/sizeof(list1))
B. print(sum(list1)/len(list1)) D. print(total(list1)/len(list1))
6. What will be the output of following Python code?
list1=["Python","Java","c","C","C++"]
print(min(list1))
A. c B. C++ C. C D. min function cannot be used on string elements
7. The elements of a list are arranged in descending order. Which of the following two will give same outputs?
i. print(list_name.sort()) ii. print(max(list_name))
iii. print(list_name.reverse()) iv. print(list_name[-1])
A. i, ii B. i, iii C. ii, iii D. iii, iv
8. What will be the result after the execution of above Python code?
list1=[3,2,5,7,3,6]
list1.pop(3)
print(list1)
A. [3,2,5,3,6] C. [2,5,7,6]
B. [2,5,7,3,6] D. [3,2,5,7,3,6]

9. What will be the output of below Python code?


list1=[1,3,5,2,4,6,2]
list1.remove(2)
print(sum(list1))
A. 18 B. 19 C. 21 D. 22
10. What will be the output of below Python code?
list1=["tom","mary","simon"]
list1.insert(5,8)
print(list1)
A. ["tom", "mary", "simon", 5] C. [8, "tom", "mary", "simon"]
B. ["tom", "mary", "simon", 8] D. Error
11. find output –
L = list('123456')
L[0] = L[5] = 0
L[3] = L[-2]
print(L)
a) [1, ‘2’, ‘3’, ‘4’, ‘5’, 6] c) [0, ‘2’, ‘3’, ‘0’, ‘0’, 0]
b) [0, ‘2’, ‘0’, ‘5’, ‘5’, 0] d) [0, ‘2’, ‘3’, ‘5’, ‘5’, 0]
12. find output
list1 = [10, 20, [300, 400, [5000, 6000], 500], 30, 40]
list1[2][2].append(7000)
print(list1)
13. Concatenate the two list indexwise –
l1 = ["M", "na", "i", "Ke"]
l2 = ["y", "me", "s", "lly"]
resultant l3 =['My', 'name', 'is', 'Kelly']
14. Concatenate two lists in the following order
list1 = ["Hello ", "take "]
list2 = ["Dear", "Sir"]
result =['Hello Dear', 'Hello Sir', 'take Dear', 'take Sir']
15. find output
list1 = [1, 2, 3, 4, 5]
list2 = list1
list2[0] = 0;
print ("list1= : ", list1 )
16. What is the output of the following program?
L1 = []
L1.append([1, [2, 3], 4])
L1.extend([7, 8, 9])
print(L1[0][1][1] + L1[2])
a) Type Error: can only concatenate list (not c) 11
“int”) to list d) 38
b) 12 Ans. (c)
Explanation: In the print(), indexing is used. L1[0] denotes [1, [2, 3], 4], L1[0][1] denotes [2, 3],
L1[0][1][1] = 3 and L1[2] = 8. Thus, the two integers are added, 3 + 8 = 11 and output comes as 11.
17. What is the output ?
L1 = [1, 1.33, 'GFG', 0, 'NO', None, 'G', True]
val1, val2 = 0, ''
for x in L1:
if(type(x) == int or type(x) == float):
val1 += x
elif(type(x) == str):
val2 += x
else:
break
print(val1, val2)
a) 2.33 GFGNO
b) 2.33 GFGNOne
c) 1.33 GFG0
d) None of the above.
18. Output ?
L1 = [1, 2, 3, 4]
L2 = L1
L3 = L1.copy()
L4 = L1
L1[0] = [5]
print(L1, L2, L3, L4)
[5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
b) [[5], 2, 3, 4] [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4]
c) [5, 2, 3, 4] [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4]
d) [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
19. T1 = (1)
T2 = (3, 4)
T1 += 5
print(T1)
print(T1 + T2)
a) TypeError b) (1, 5, 3, 4)
c) 1 TypeError d) 6 TypeError
20. T = (1, 2, 3, 4, 5, 6, 7, 8)
print(T[T.index(5)], end = " ")
print(T[T[T[6]-3]-6])
a) 4 0 c) 5 IndexError
b) 5 8 d) 4 1
21. def REVERSE(L):
L.reverse()
return(L)
def YKNJS(L):
List = []
List.extend(REVERSE(L))
print(List)

L = [1, 3.1, 5.31, 7.531]


YKNJS(L)
a) [1, 3.1, 5.31, 7.531]
b) [7.531, 5.31, 3.1, 1]
c) IndexError
d) AttributeError: ‘NoneType’ object has no attribute ‘REVERSE’
22. from math import sqrt
L1 = [x**2 for x in range(10)].pop()
L1 + = 19
print(sqrt(L1), end = " ")
L1 = [x**2 for x in reversed(range(10))].pop()
L1 + = 16
print(int(sqrt(L1)))
a) 10.0 4.0 b) 4.3588 4 c) 10 .0 4 d) 10.0 0
23. What is the output of the following program?
L = list('123456')
L[0] = L[5] = 0
L[3] = L[-2]
print(L)
a) [0, ‘2’, ‘3’, ‘4’, ‘5’, 0] c) [‘0’, ‘2’, ‘3’, ‘5’, ‘5’, ‘0’]
b) [‘6’, ‘2’, ‘3’, ‘5’, ‘5’, ‘6’] d) [0, ‘2’, ‘3’, ‘5’, ‘5’, 0]
24. What is the output of the following program?
T = 'geeks'
a, b, c, d, e = T
b = c = '*'
T = (a, b, c, d, e)
print(T)
a) (‘g’, ‘*’, ‘*’, ‘k’, ‘s’) c) (‘geeks’, ‘*’, ‘*’)
b) (‘g’, ‘e’, ‘e’, ‘k’, ‘s’) d) KeyError
25. What is the value of L at the end of execution of the following program?
L = [2e-04, 'a', False, 87]
T = (6.22, 'boy', True, 554)
for i in range(len(L)):
if L[i]:
L[i] = L[i] + T[i]
else:
T[i] = L[i] + T[i]
break
a) [6.222e-04, ‘aboy’, True, 641] c) TypeError
b) [6.2202, ‘aboy’, 1, 641] d) [6.2202, ‘aboy’, False, 87]
26. What is the output of the following program?
T = (2e-04, True, False, 8, 1.001, True)
val = 0
for x in T:
val += int(x)
print(val)
a) 12 c) 11.001199999999999
b) 11 d) TypeError
27. Which of the options below could possibly be the output of the following program?
L = [3, 1, 2, 4]
T = ('A', 'b', 'c', 'd')
L.sort()
counter = 0
for x in T:
L[counter] += int(x)
counter += 1
break
print(L)
a) [66, 97, 99, 101] b) [66, 68, 70, 72]
c) [66, 67, 68, 69] d) ValueError’

28. What is the output of the following program?


data = [2, 3, 9]
temp = [[x for x in[data]] for x in range(3)]
print (temp)

a) [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]] c) [[[2, 3, 9]], [[2, 3, 9]]]
b) [[2, 3, 9], [2, 3, 9], [2, 3, 9]] d) None of these
29. What is the output of the following program?
data = [x for x in range(5)]
temp = [x for x in range(7) if x in data and x%2==0]
print(temp)

a) [0, 2, 4, 6] c) [0, 1, 2, 3, 4, 5]
b) [0, 2, 4] d) Runtime error
30. What is the output of the following program?
temp = ['Geeks', 'for', 'Geeks']
arr = [i[0].upper() for i in temp]
print(arr)

a) [‘G’, ‘F’, ‘G’] c) [‘GEEKS’, ‘FOR’, ‘GEEKS’]


b) [‘GEEKS’] d) Compilation error
31. Whats is the output of the following program?
temp = 'Geeks 22536 for 445 Geeks'
data = [x for x in (int(x) for x in temp if x.isdigit()) if x%2 == 0]
print(data)

a) [2, 2, 6, 4, 4] c) Runtime error


b) Compilation error d) [‘2’, ‘2’, ‘5’, ‘3’, ‘6’, ‘4’, ‘4’, ‘5’]
32. What is the output of the following program?
data = [x for x in (x for x in 'Geeks 22966 for Geeks' if x.isdigit()) if
(x in ([x for x in range(20)]))]
print(data)
a) [2, 2, 9, 6, 6] c) Compilation error
b) [] d) Runtime error

You might also like