Home / Programming Questions / Python MCQs / Page 4

Python MCQs with answers Page - 4

Dear candidates you will find MCQ questions of Python here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

R

Ram Sharma • 178.09K 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

R

Ram Sharma • 178.09K 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}

R

Ram Sharma • 178.09K Points
Coach

Q. What is the output of the following program?

Code:
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}
D['1'] = 2
print(D[D[D[str(D[1])]]])
(A) 2
(B) 3
(C) „2?
(D) KeyError

R

Ram Sharma • 178.09K 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

R

Ram Sharma • 178.09K 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

R

Ram Sharma • 178.09K Points
Coach

Q. What is the output of the following program?

Code:
import string
import string
Line1 = "And Then There Were None"
Line2 = "Famous In Love"
Line3 = "Famous Were The Kol And Klaus"
Line4 = Line1 + Line2 + Line3
print(string.find(Line1, 'Were'), string.count((Line4), 'And'))
(A) True 1
(B) 15 2
(C) (15, 2)
(D) True 2

R

Ram Sharma • 178.09K Points
Coach

Q. What is the output of the following program?

Code:
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ')
(A) [„What?, „will?, „have?, „so?, „will?]
(B) Wh t will h ve so will
(C) What will have so will
(D) [„Wh?, „t will h?, „ve so will?]

R

Ram Sharma • 178.09K Points
Coach

Q. What is the type of each element in sys.argv?

(A) set
(B) list
(C) tuple
(D) string

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.