100% found this document useful (1 vote)
197 views

Python Programming Set 1

The document contains 25 multiple choice questions about Python programming. The questions cover topics like data types, operators, functions, strings, lists, dictionaries, tuples, and more. Each question is followed by 4 answer options and the correct answer. The questions test fundamental Python concepts and syntax.

Uploaded by

Manish Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
197 views

Python Programming Set 1

The document contains 25 multiple choice questions about Python programming. The questions cover topics like data types, operators, functions, strings, lists, dictionaries, tuples, and more. Each question is followed by 4 answer options and the correct answer. The questions test fundamental Python concepts and syntax.

Uploaded by

Manish Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Python Programming MCQs [set-1]

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


A. 4.5
B. 4.0
C. 4
D. Error
Answer: C

2. Which function overloads the >> operator?


A. more()
B. gt()
C. ge()
o m
D. rshift() . c
Answer: D
te
3. What is the output of the followingM
a
program :
i=0
c q
while i < 3:
print i
M
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

4. Which module in Python supports regular expressions?


A. re
B. regex
C. pyregex
D. None of the above
Answer: A
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
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

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


A. List
B. Dictionary
C. Tuple
D. Array
Answer: A

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

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

View all MCQ's at McqMate.com


A. 27
B. 9
C. 3
D. 1
Answer: C

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

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

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

13. What is the output of the following program :


i=0
while i < 5:
print(i)

View all MCQ's at McqMate.com


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

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


A. („cd?)
B. (”)
C. („cd?, ”, ”)
D. (”, „cd?, ”)
Answer: D

15. What is the output of the following program : print 'abcefd'.replace('cd', '12')
A. ab1ef2
B. abcefd
C. ab1efd
D. ab12ed2
Answer: B

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

View all MCQ's at McqMate.com


Answer: D

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

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

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():

View all MCQ's at McqMate.com


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

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

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

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]

View all MCQ's at McqMate.com


D. [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
Answer: D

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

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

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]

View all MCQ's at McqMate.com


D. 5 None [1, 3, 7, 9]
Answer: A

View all MCQ's at McqMate.com

You might also like