Python Programming Solved MCQs

1.

What is the output of the following code : print 9//2

A. 4.5
B. 4.0
C. 4
D. Error
Answer» C. 4
2.

Which function overloads the >> operator?

A. more()
B. gt()
C. ge()
D. rshift()
Answer» D. rshift()
3.

What is the output of the following program :
i = 0
while i < 3:
print i
print i+1

A. 0 2 1 3 2 4
B. 0 1 2 3 4 5
C. 0 1 1 2 2 3
D. 1 0 2 4 3 5
Answer» C. 0 1 1 2 2 3
4.

Which module in Python supports regular expressions?

A. re
B. regex
C. pyregex
D. None of the above
Answer» A. re
5.

What is the output of the following program : print 0.1 + 0.2 == 0.3

A. True
B. False
C. Machine dependent
D. Error
Answer» B. False
Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The
round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17
between (0.1 + 0.2) and 0.3.
6.

Which of these is not a core data type?

A. Lists
B. Dictionary
C. Tuples
D. Class
Answer» D. Class
7.

What data type is the object below? L = [1, 23, „hello‟, 1]

A. List
B. Dictionary
C. Tuple
D. Array
Answer» A. List
8.

What is the output of the following program :
def myfunc(a):
a = a + 2
a = a * 2
return a
print myfunc(2)

A. 8
B. 16
C. Indentation Error
D. Runtime Error
Answer» C. Indentation Error
9.

What is the output of the expression : 3*1**3

A. 27
B. 9
C. 3
D. 1
Answer» C. 3
10.

What is the output of the following program : print '{0:.2}'.format(1.0 / 3)

A. 0.333333
B. 0.33
C. 0.333333:-2
D. Error
Answer» B. 0.33
11.

What is the output of the following program : print '{0:-2%}'.format(1.0 / 3)

A. 0.33
B. 0.33%
C. 33.33%
D. 33%
Answer» C. 33.33%
12.

What is the output of the following program :
i = 0
while i < 3:
print i
i += 1
else:
print 0

A. 0 1 2 3 0
B. 0 1 2 0
C. 0 1 2
D. Error
Answer» B. 0 1 2 0
13.

What is the output of the following program :
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

A. 0 1 2 0
B. 0 1 2
C. Error
D. None of the above
Answer» B. 0 1 2
14.

What is the output of the following program : print 'cd'.partition('cd')

A. („cd‟)
B. (”)
C. („cd‟, ”, ”)
D. (”, „cd‟, ”)
Answer» D. (”, „cd‟, ”)
15.

What is the output of the following program : print 'abcefd'.replace('cd', '12')

A. ab1ef2
B. abcefd
C. ab1efd
D. ab12ed2
Answer» B. abcefd
16.

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])

A. 1 1
B. 1 44
C. 3 1
D. 3 44
Answer» D. 3 44
17.

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)

A. Compilation error
B. Runtime error
C. („Google‟, 1) („Facebook‟, 2) („Youtube‟, 3) („Microsoft‟, 2) („GFG‟, 1)
D. None of these
Answer» C. („Google‟, 1) („Facebook‟, 2) („Youtube‟, 3) („Microsoft‟, 2) („GFG‟, 1)
18.

What is the output of the following program?
dictionary1 = {'GFG' : 1,
'Google' : 2,
'GFG' : 3
}
print(dictionary1['GFG']);

A. Compilation error due to duplicate keys
B. Runtime time error due to duplicate keys
C. 3
D. 1
Answer» C. 3
19.

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 = "")

A. Compilation error
B. {„key1‟: 44, „key2‟: 566}[1, 2, 3, 4]
C. Runtime error
D. None of the above
Answer» B. {„key1‟: 44, „key2‟: 566}[1, 2, 3, 4]
20.

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
Answer» A. [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]]
21.

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
Answer» B. [0, 2, 4]
22.

What is the output of the following program?
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]
Answer» D. [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
23.

What is the output of the following program?
import sys
L1 = 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
Answer» C. 48 64 72 128
24.

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
Answer» B. 5 8
25.

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]
Answer» A. 5 None [3, 7, 9]
Tags
Question and answers in Python Programming, Python Programming multiple choice questions and answers, Python Programming Important MCQs, Solved MCQs for Python Programming, Python Programming MCQs with answers PDF download

We need your help!

We're developing a website for study materials for students.
We would love to hear your answers to some of the questions.

Take Survey