Top 50+ Solved Python Programming MCQ Questions Answer
Q. 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]]]
b. [[2, 3, 9], [2, 3, 9], [2, 3, 9]]
c. [[[2, 3, 9]], [[2, 3, 9]]]
d. None of these
Q. 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]
b. [0, 2, 4]
c. [0, 1, 2, 3, 4, 5]
d. Runtime error
Q. What is the output of the following program?L1 = [1, 2, 3, 4]L2 = L1L3 = L1.copy()L4 = list(L1)L1[0] = [5]print(L1, L2, L3, L4)
a. [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]
Q. What is the output of the following program?import sysL1 = tuple()print(sys.getsizeof(L1), end = " ")L1 = (1, 2)print(sys.getsizeof(L1), end = " ")L1 = (1, 3, (4, 5))print(sys.getsizeof(L1), end = " ")L1 = (1, 2, 3, 4, 5, [3, 4], 'p', '8', 9.777, (1, 3))print(sys.getsizeof(L1))
a. 0 2 3 10
b. 32 34 35 42
c. 48 64 72 128
d. 48 144 192 480
Q. What is the output of the following program?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
b. 5 8
c. 5 IndexError
d. 4 1
Q. What is the output of the following program?L = [1, 3, 5, 7, 9]print(L.pop(-3), end = ' ')print(L.remove(L[0]), end = ' ')print(L)
a. 5 None [3, 7, 9]
b. 5 1 [3, 7, 9]
c. 5 1 [3, 7, 9]
d. 5 None [1, 3, 7, 9]
Q. What is the output of the following program?D = dict()for x in enumerate(range(2)): D[x[0]] = x[1] D[x[1]+7] = x[0]print(D)
a. KeyError
b. {0: 1, 7: 0, 1: 1, 8: 0}
c. {0: 0, 7: 0, 1: 1, 8: 1}
d. {1: 1, 7: 2, 0: 1, 8: 1}
Q. What is the output of the following program?D = dict()for i in range (3): for j in range(2): D[i] = jprint(D)
a. {0: 0, 1: 0, 2: 0}
b. {0: 1, 1: 1, 2: 1}
c. {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
d. TypeError: Immutable object
Q. What is the output of the following program? from math import *a = 2.13b = 3.7777c = -3.12print(int(a), floor(b), ceil(c), fabs(c))
a. 2 3 -4 3
b. 2 3 -3 3.12
c. 2 4 -3 3
d. 2 3 -4 3.12
Q. What is the output of the following program?import stringimport stringLine1 = "And Then There Were None"Line2 = "Famous In Love"Line3 = "Famous Were The Kol And Klaus"Line4 = Line1 + Line2 + Line3print(string.find(Line1, 'Were'), string.count((Line4), 'And'))
a. True 1
b. 15 2
c. (15, 2)
d. True 2
Q. What is the length of sys.argv?
a. number of arguments
b. number of arguments + 1
c. number of arguments – 1
d. none of the mentioned
Q. What is the output of the following code?def foo(k): k[0] = 1q = [0]foo(q)print(q)
a. [0].
b. [1].
c. [1, 0].
d. [0, 1].
Q. What is the output of the following code?def foo(fname, val): print(fname(val))foo(max, [1, 2, 3])foo(min, [1, 2, 3])
a. 3 1
b. 1 3
c. error
d. none of the mentioned