Python Programming MCQs | Page - 2
Dear candidates you will find MCQ questions of Python Programming 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.
β
Correct Answer: (C)
33.33%
Q. What is the output of the following program :
i = 0
while i < 3:
print i
i += 1
else:
print 0
β
Correct Answer: (B)
0 1 2 0
Q. What is the output of the following program :
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
β
Correct Answer: (B)
0 1 2
Q. What is the output of the following program : print 'cd'.partition('cd')
β
Correct Answer: (D)
(”, „cdβ, ”)
Q. What is the output of the following program : print 'abcefd'.replace('cd', '12')
β
Correct Answer: (B)
abcefd
Q. What will be displayed by the following code?
def f(value, values):
v = 1
values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
β
Correct Answer: (D)
3 44
Q. Predict the output of following python programs
dictionary1 = {'Google' : 1,
'Facebook' : 2,
'Microsoft' : 3
}
dictionary2 = {'GFG' : 1,
'Microsoft' : 2,
'Youtube' : 3
}
dictionary1.update(dictionary2);
for key, values in dictionary1.items():
print(key, values)
β
Correct Answer: (C)
(„Googleβ, 1) („Facebookβ, 2) („Youtubeβ, 3) („Microsoftβ, 2) („GFGβ, 1)
Q. What is the output of the following program?
dictionary1 = {'GFG' : 1,
'Google' : 2,
'GFG' : 3
}
print(dictionary1['GFG']);
β
Correct Answer: (C)
3
Q. What is the output of the following program?
temp = dict()
temp['key1'] = {'key1' : 44, 'key2' : 566}
temp['key2'] = [1, 2, 3, 4]
for (key, values) in temp.items():
print(values, end = "")
β
Correct Answer: (B)
{„key1β: 44, „key2β: 566}[1, 2, 3, 4]
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)
β
Correct Answer: (A)
[[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]]
Jump to