Python MCQs with answers Page - 2

Here, you will find a collection of MCQ questions on Python. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
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

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
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

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
L1 = [1, 2, 3, 4]
L2 = L1
L3 = 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]

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
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

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
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]

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program? def REVERSE(L):

Code:
L.reverse()
return(L)
def YKNJS(L):
List = 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?

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
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

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
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}

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(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

A

Admin • 828.03K Points
Coach

Q. What is the output of the following program?

Code:
from math import *
a = 2.13
b = 3.7777
c = -3.12
print(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