250 Python Quizzes
250 Python Quizzes
250
a
MULTIPLE CHOICES
Thanks a lot for purchasing our book. We are thrilled to present this compilation of 250
engaging and thought-provoking Python quizzes that are certain to challenge and enrich
your understanding of this versatile programming language.
Countless hours were invested in researching, designing, and refining each question to
ensure that they test your knowledge and inspire a deeper exploration of Python's concepts.
We wanted to provide a resource that caters to both beginners seeking to solidify their basics
and seasoned developers aiming to challenge their expertise.
Your support gives us a lot of confidence. As freelancers, we've poured our passion into this
book, and your appreciation fuels our drive to create more valuable content. If you find this
book beneficial and wish to extend your support, we kindly invite you to consider supporting
this project financially through our Buy Me A Coffee page. Every contribution, no matter how
small, goes a long way in helping us continue our mission of spreading knowledge.
For any doubts and clarifications, we encourage you to connect with us on LinkedIn. We
create content on different platforms like Medium, Gumroad, and LinkedIn. You can follow us
through these links to consume more Python content. You can get my free Python
Handwritten Notes from Gumroad as well which has over 2900 sales. Get to know all our
work through our LinkTree account.
We believe that learning should be an immersive and enjoyable experience, and we hope that
this philosophy shines through in every quiz we've crafted. Happy Coding !!!
01
Table of Contents 250 Python Quizzes
Table of Contents
01 Introduction to Python
02 The Print Function
03 Variables and Keywords - 01
04 Variables and Keywords - 02
05 Data Types - 01
06 Data Types - 02
07 Operators and Expressions
08 Decision-Making Statements
09 Looping Statements
10 Strings - 01
11 Strings - 02
12 Strings - 03
13 Lists - 01
14 Lists - 02
15 Lists - 03
16 Tuples
17 Sets
18 Dictionaries
19 User Defined Functions
20 Errors and Exceptions
21 Built-in Functions - 01
22 Built-in Functions - 02
23 Modules and Packages
24 Object Oriented Programming
25 File Handling
26 Correct Answers
02
Introduction to Python 250 Python Quizzes
Introduction to Python
A) Dennis Ritchie
B) Bjarne Stroustrup
C) Guido van Rossum
D) James Gosling
A) .pyth
B) .p
C) .python
D) .py
A) 1989
B) 1991
C) 1987
D) 1994
A) Interpreted
B) Compiled
C) Both Compiled and Interpreted
D) None of the Above
03
Introduction to Python 250 Python Quizzes
05. There are ____ keywords in Python 3.11 (currently the latest version).
A) 33
B) 35
C) 30
D) 38
A) #
B) !
C) *
D) /
A) print()
B) sqrt()
C) ascii()
D) sorted()
A) Machine Learning
B) Data Science
C) Web Development
D) All of the Above
04
Introduction to Python 250 Python Quizzes
A) PyCharm
B) Visual Studio Code
C) IDLE
D) Jupyter Notebook
05
The Print Function 250 Python Quizzes
print('pyt.', 'hon')
A) python
B) pyt. hon
C) pyt hon
D) pyt.hon
print('10' + '20')
A) 10 20
B) 1020
C) 30
D) 10 + 20
03. Choose the correct code that would display the following output.
ABBBC
06
The Print Function 250 Python Quizzes
04. What is the default value of the 'end' argument used in the print( ) function?
A) end=' '
B) end='\n'
C) end=','
D) end='\t'
A) Hello World
B) Hello World%
C) Hello%World
D) Error
A) code*blocks*
B) code*blocks
C) code blocks*
D) Error
07. Choose the correct code that would display the following output.
lemon+cake+
07
The Print Function 250 Python Quizzes
08. Which of the following arguments is not a part of the print( ) function?
A) key
B) flush
C) end
D) file
09. Choose the correct code that would display the following output.
c a t
10. What is the default value of the 'sep' argument used in the print( ) function?
A) sep='\t'
B) sep=','
C) sep=' '
D) sep='\n'
08
Variables and Keywords - 01 250 Python Quizzes
A) yield
B) true
C) C31
D) a_b_c
02. What is the correct Python syntax to store the value 347 in a variable named n?
A) n == 347
B) 347 = n
C) int n = 347
D) n = 347
A) var%
B) none
C) pass
D) 8num
a = 100
b = 200
b = a
a = b
print(b, a)
A) 100 200
B) 200 100
C) 100 100
D) 200 200
09
Variables and Keywords - 01 250 Python Quizzes
p = q
q = 'hello'
print(p)
A) hello
B) q
C) Blank Output
D) Error
A) except
B) final
C) from
D) global
r = 5 + 8
print('r')
A) 5 + 8
B) r
C) 13
D) Error
08. How many keywords (as of Python 3.11) are not completely lowercase?
A) 2
B) 5
C) 3
D) 4
010
Variables and Keywords - 01 250 Python Quizzes
A) Iterator
B) Identifier
C) Literal
D) Operator
10. What must be the input given to m in order to get 8 as the output?
m = int(input())
n = m * 3
p = n - 4
q = p + m
print(q)
A) 3
B) 5
C) 8
D) 0
011
Variables and Keywords - 02 250 Python Quizzes
A) is
B) in
C) or
D) as
02. What is the syntax to assign the number 76 to variables r, s, and t using a single line?
A) r + s + t = 76
B) r = s = t = 76
C) r, s, t = 76
D) r, s, t = 76 * 3
A) y z x
B) x y z
C) x x z
D) y x z
A) default
B) del
C) false
D) local
012
Variables and Keywords - 02 250 Python Quizzes
a, b, c = 3, 8, 5
d = b - c
b = d + a
a = b - c
print(d, a, b, c)
A) 1 6 5 3
B) 3 1 6 5
C) 3 3 8 5
D) 3 1 8 5
06. On executing the following code, how many objects has Python created?
val = 'code'
var = val
A) 0
B) 3
C) 2
D) 1
07. On executing the following code, how many references has Python created?
val = 758
var = val
A) 2
B) 0
C) 3
D) 1
013
Variables and Keywords - 02 250 Python Quizzes
c = 'choco'
d = 'bar'
c, d = d, c
print(c, d)
A) bar choco
B) choco choco
C) bar bar
D) choco bar
g = 'goat'
print(*g)
A) g o a t
B) g
C) goat
D) Error
A) break
B) pass
C) case
D) async
014
Data Types - 01 250 Python Quizzes
Data Types - 01
A) dict
B) dictionary
C) dic
D) dicts
A) ('A')
B) 10, 20
C) ([10], [20])
D) (10,)
a = 00
print(list(str(a))
A) ['00']
B) ['0']
C) ['0', '0']
D) Error
015
Data Types - 01 250 Python Quizzes
data = '20.0',
Print(type(data))
A) <class 'int'>
B) <class 'float'>
C) <class 'str'>
D) <class 'tuple'>
A) 9.5e-3
B) 9.5e3
C) 95e-2
D) 0.95e-1
A) String to List
B) Integer to Float
C) Tuple to List
D) Float to Integer
016
Data Types - 01 250 Python Quizzes
r = 3
s = 5
print(str(s + r))
A) 35
B) 8
C) 53
D) Error
print(isinstance('true', bool))
A) True
B) False
C) true
D) Error
017
Data Types - 02 250 Python Quizzes
Data Types - 02
A) Integer
B) Dictionary
C) Complex
D) String
A) []
B) set()
C) {}
D) ()
a = '01.01'
print(int(a))
A) 01
B) 1
C) 1.01
D) Error
04. Which of the following data type conversion is not possible in Python?
A) String to Integer
B) List to Tuple
C) List to Integer
D) Complex to String
018
Data Types - 02 250 Python Quizzes
num = 6
print(complex(num))
A) 6.0
B) 6j
C) 6+0j
D) Error
s = '123'
print(list(s))
A) [1, 2, 3]
B) [123]
C) ['1', '2', '3']
D) ['123']
var = '100'
print(int(var, 2))
A) 100
B) 2
C) 4
D) Error
019
Data Types - 02 250 Python Quizzes
08. Which value would become False when converted to a boolean value?
A) [0]
B) 1.0e0
C) 1+0j
D) (0)
A) (10, 12)
B) (5, 6)
C) (5, 10, 6, 12)
D) Error
b = True + True
print(b)
A) 2
B) TrueTrue
C) 1
D) True
020
Operators and Expressions 250 Python Quizzes
A) !=
B) <<
C) >=
D) ==
s = 'HdaPKwTb'
a = 'ab' not in s
b = 'p' in s
print(a, b)
A) True False
B) True True
C) False False
D) False True
x = 35
y = 40
x += y
y *= 2
print(x, y)
A) 35 70
B) 75 150
C) 35 40
D) 75 80
021
Operators and Expressions 250 Python Quizzes
A) &
B) or
C) |
D) =
A) **
B) <
C) not
D) is
A) 1
B) True
C) False
D) 0
print(7 - 5 * (3 > 4) + 2)
A) 0
B) 2
C) 9
D) 5
022
Operators and Expressions 250 Python Quizzes
08. Which among the following operators has the lowest precedence?
A) **
B) +
C) and
D) in
print(2 ** 3 ** 2)
A) 512
B) 64
C) 256
D) 16
m = [1, 2]
n = [1, 2]
o = 10
p = 10
print(m is n, o is p)
A) True False
B) True True
C) False False
D) False True
023
Decision-Making Statements 250 Python Quizzes
Decision-Making Statements
01. What is the recommended number of spaces used for indentation in Python?
A) 2
B) 4
C) 1
D) 8
x = input()
if x != 9:
print(x, end=' ')
print(7)
A) 7 9
B) 9
C) 7
D) 9 7
k = 15
if k = 13:
print(k + 2)
else:
print(k - 2)
A) 13
B) 11
C) 15
D) Error
024
Decision-Making Statements 250 Python Quizzes
04. Which block is an optional alternative to the if block that must also have a condition?
A) else
B) elif
C) if
D) case
A) False
B) 3
C) 1
D) Error
a = 3
if a - 3:
print(a * a)
else:
print(a + a)
A) 6
B) 0
C) 9
D) Error
A) Underscore (_)
B) Asterisk (*)
C) Pipeline (|)
D) Percentage (%)
025
Decision-Making Statements 250 Python Quizzes
m = int(input())
match m:
case 1:
print(3, end=' ')
case 2:
print(1, end=' ')
case 3:
print(2, end=' ')
print(m)
A) 1 2
B) 3 2
C) 2 1
D) 2 2
09. Fill the question mark with the correct condition to get the given output.
r = 25
if ?:
print(r, end=' ')
print(r * 2)
Output:
25 50
A) r % 2 == 0
B) r % 5 != 0
C) r % 2 == 1
D) r % 5 == 1
026
Decision-Making Statements 250 Python Quizzes
b = int('D', 16)
match b - 1:
case 11 | 14:
print('Gold', end=' ')
case 13 | 10:
print('Silver', end=' ')
case 12 | 15:
print('Bronze', end=' ')
print(b)
A) Bronze 13
B) Gold 14
C) Silver 13
D) Bronze 12
027
Looping Statements 250 Python Quizzes
Looping Statements
s = 4
while s < 9:
s = s + 1
print(s, end='-')
A) 4-5-6-7-8-
B) 5-6-7-8-
C) 4-5-6-7-8-9-
D) 5-6-7-8-9-
A) 15&11&
B) 26&
C) 14&12&
D) Error
03. How many times does the given loop get executed?
A) 5
B) 3
C) 6
D) 4
028
Looping Statements 250 Python Quizzes
for i in range(1):
print(i, end=' ')
A) 1
B) 0 1
C) Blank Output
D) 0
05. Fill the question mark with the suitable code to get the given output.
for z in ?:
print(z, end=' ')
Output:
7 5
A) range(7, 5, -2)
B) range(4, 7, -2)
C) range(5, 7, -2)
D) range(7, 3, -2)
a = 6
while a > 8:
print(a, end=' ')
a = a - 1
A) Infinite Loop
B) 6 7
C) Blank Output
D) Error
029
Looping Statements 250 Python Quizzes
for x in range(3):
print(x, end=' ')
x = 3
A) 0 3 3
B) 0 1 2
C) 0
D) Error
A) 10 20 30
B) 10 20 30 40
C) 10 20
D) 10 20 40
09. Fill the question mark with the condition to make the loop run infinitely.
r = 0
while ?:
print(r)
r = r + 2
A) r <= 0
B) r > 0
C) r >= 0
D) r < 0
030
Looping Statements 250 Python Quizzes
10. Which keyword, when encountered, skips the current iteration in a loop?
A) continue
B) else
C) break
D) pass
031
Strings - 01 250 Python Quizzes
Strings - 01
A) capital()
B) caps()
C) uppercase()
D) upper()
02. Choose the correct code that would display the following output.
ZZZ
m = 'chipsized'
print(m[-5], m[5])
A) p i
B) s i
C) p s
D) s s
04. Which of the following string methods does not return an integer?
A) count()
B) find()
C) replace()
D) index()
032
Strings - 01 250 Python Quizzes
k = 'internet'
print(k[5:9])
A) net
B) netne
C) rnet
D) Error
i = 'ice'
print(f'{i} coffee')
A) {i} coffee
B) i coffee
C) {ice} coffee
D) ice coffee
07. Choose the correct code that would display the following output.
533
A) print('353533535'[6::-2])
B) print('353533535'[::-4])
C) print('353533535'[8:3:-2])
D) print('353533535'[3:5])
08. Which of the following code doesn't produce ppl as the output?
A) print('apple'[1:4])
B) print('apple'[::-1][3:0:-1])
C) print('apple'[-4:-2])
D) print('apple'[1:7][:3])
033
Strings - 01 250 Python Quizzes
r = 'peace'
print('y'.join(r))
A) pyeyaycyey
B) peacey
C) pyeyaycye
D) ypeace
m = 'code'
print(m[1:3:2])
A) ode
B) o
C) code
D) oe
034
Strings - 02 250 Python Quizzes
Strings - 02
y = 'chocolate'
print(y[::-3][-3])
A) o
B) l
C) c
D) e
h = 'hardware'
print(h.split('a'))
A) ['h', 'rdware']
B) ['h', 'a', 'rdw', 'a', 're']
C) ['h', 'rdw', 're']
D) ['h', 'ardw', 'are']
t = 'programmers'
print(t.replace('r', 'l', 2))
A) ploglammels
B) ploglammers
C) proglammers
D) proglammels
035
Strings - 02 250 Python Quizzes
04. Which of the following statements would print two backslashes to the output?
A) print('\2b')
B) print('\\\\')
C) print('\\')
D) print('\\\')
s = 'welcome'
print(s.index('e', 3))
A) 1
B) 3
C) 2
D) 6
b = 'pythonista'
print(b[2:5:0])
A) thon
B) tho
C) Blank Output
D) Error
07. Which of the following code slices iwd from the following string?
j = 'sandwich'
A) j[-3:2:-1]
B) j[-2:2:-1]
C) j[-3:3:-1]
D) j[-2:3:-1]
036
Strings - 02 250 Python Quizzes
a = 'bOokKEepEr'
print(a.swapcase().count('e'))
A) 1
B) 3
C) 0
D) 2
n = 'python quiz'
print(n.title())
A) PYTHON QUIZ
B) Python Quiz
C) PYTHON quiz
D) Python quiz
p = 'google'
print(p[-7::2])
A) log
B) oge
C) gol
D) ego
037
Strings - 03 250 Python Quizzes
Strings - 03
e = 'origin'
print(e.split('i', 1))
A) ['orig', 'n']
B) ['or', 'g', 'n']
C) ['or', 'gin']
D) Error
x = 'coding'
print(x[-4:4:-1])
A) nid
B) di
C) ni
D) Blank Output
y = 'start'
print(y.startswith('t', 1))
A) True
B) t
C) 1
D) False
038
Strings - 03 250 Python Quizzes
A) casefold()
B) find()
C) remove()
D) center()
f = 'download'
f.replace('d', 'x')
print(f)
A) download
B) xownload
C) xownloax
D) Error
print('s'.join('run').count('s'))
A) 1
B) 2
C) 3
D) 4
print(r'chip\'s question')
A) chip's question
B) r'chip\'s question'
C) chip\'s question
D) Error
039
Strings - 03 250 Python Quizzes
v = "650"
print(v.zfill(4))
A) 0065000
B) 6500
C) 0650
D) 6500000
c = "cracked"
print(c[1:5][1:3])
A) rac
B) ac
C) rack
D) ack
x = "developer"
print(x.partition('o'))
040
Lists - 01 250 Python Quizzes
Lists - 01
A) ['C', 'D']
B) ['A', 'B', ['C', 'D']]
C) ['A', 'B', 'C']
D) ['A', 'B']
m = [1, 2, 3, 4]
m.insert(2, 3)
print(m)
A) [1, 2, 3, 3, 4]
B) [1, 2, 3, 4]
C) [1, 2, 3, 2, 4]
D) [1, 2, 2, 3, 4]
c = [5, 9, 4]
c[1:2] = [6, 8, 3]
print(c)
A) [5, 6, 4]
B) [5, 6, 8, 3, 4]
C) [5, 6, 8]
D) Error
041
Lists - 01 250 Python Quizzes
z = [2, 7, 6]
z.append([8, 9])
print(z)
A) [2, 7, 6, 8, 9]
B) [2, 8, 9]
C) [2, 7, 6, [8, 9]]
D) Error
r = [1, 3, 4, 3, 2]
print(r.index(3, 4))
A) 3
B) 2
C) 1
D) Error
i = [30, 40]
print(i + i)
042
Lists - 01 250 Python Quizzes
b = [0, 3, 1, 4, 0]
b.remove(2)
print(b)
A) [3, 1, 4]
B) [0, 3, 1, 4, 0]
C) [0, 3, 4, 0]
D) Error
043
Lists - 01 250 Python Quizzes
10. Which concept is used in the first line of the given code?
A) List Unpacking
B) List Comprehension
C) List Generation
D) List Iteration
044
Lists - 02 250 Python Quizzes
Lists - 02
01. Which of the following code accesses the value 3 from the given list?
A) h[2][0]
B) h[3][1]
C) h[3][2]
D) h[2][1]
g = [1, 2, 3, 2, 5]
g.remove(2)
print(g)
A) [1, 3, 2, 5]
B) [1, 2, 2, 5]
C) [1, 3, 5]
D) [1, 2, 3, 5]
n = [76, 24]
p = n.copy()
n.pop()
print(p, n)
045
Lists - 02 250 Python Quizzes
k = [2, 1, 0, 3, 0, 2, 1]
print(k.count(k.index(0)))
A) 2
B) 1
C) 0
D) 3
a = [1, 2, 3, 4, 5]
print(a[:4].pop())
A) [1, 2, 3, 4]
B) 4
C) [1, 2, 3, 5]
D) 5
046
Lists - 02 250 Python Quizzes
07. Fill the question mark with the suitable code to get the given output.
Output:
[10, 20, 30, [40, 50]]
A) i.append([40, 50])
B) i.extend(40, 50)
C) i.append(40, 50)
D) i.extend([40, 50])
08. Fill the question mark with the suitable code for the output to be 24.
A) d.pop(24)
B) d.remove(24)
C) d.pop()
D) d.remove(3)
A) [20, []]
B) [20]
C) [20, [], 60, 80]
D) Error
047
Lists - 02 250 Python Quizzes
10. Which of the following list methods does not return None?
A) insert()
B) remove()
C) pop()
D) extend()
048
Lists - 03 250 Python Quizzes
Lists - 03
e = ['3']
e.extend('456')
print(e)
A) ['3', '456']
B) ['3456']
C) ['3', '4', '5', '6']
D) Error
j = [45]
k = j
k.append(32)
print(j, k)
049
Lists - 03 250 Python Quizzes
y = [[1, 2]]
print(y * 2)
A) [1, 2, 1, 2]
B) [[1, 2], [1, 2]]
C) [1, 1, 2, 2]
D) [[1, 1], [2, 2]]
06. Fill the question mark with the suitable code to get the given output.
Output:
[12, 14, [24], 18, 20]
A) c[2:3] = [24]
B) c[-3] = [24]
C) c[2] = 24
D) c[2:2] = [24]
050
Lists - 03 250 Python Quizzes
g = [8, 3, 9, 0, 7]
g.clear()
print(g)
A) [8, 3, 9, 0]
B) []
C) Blank Output
D) Error
s = [3, 2, 4, 5, 1]
x = s.pop(2)
print(s[-x])
A) 4
B) 2
C) 5
D) 3
09. Fill the question mark with the suitable code to get the given output.
Output:
[54, 65, 76, 87]
A) a.insert(5, 87)
B) a.extend(87)
C) a.insert(2, 87)
D) a.append([87])
051
Lists - 03 250 Python Quizzes
052
Tuples 250 Python Quizzes
Tuples
b = 'awesome',
print(b[:-2])
A) aweso
B) ()
C) ('awesome',)
D) me
A) (23, 67)
B) (23)
C) (56, 67)
D) Error
r, *s, t = (1, 2, 3, 4, 5)
print(s)
A) [2, 3, 4]
B) 2
C) 4
D) (2, 3, 4)
053
Tuples 250 Python Quizzes
04. Fill the question mark with the suitable code to get the given output.
n = (4, 2, 3, 2, 4, 3)
print(?)
Output:
2
A) n.index(2, 2)
B) n.index(2, 3)
C) n.index(3, 3)
D) n.index(3, 2)
a = (4,)
print((a + a) * 2)
A) (4, 4, 4)
B) (16)
C) (4, 4, 4, 4)
D) (4, 4)
A) 2
B) 3
C) 1
D) 0
054
Tuples 250 Python Quizzes
m = (2, 3, 4, 3, 1, 3)
print(m.index(3, 2, 4))
A) 3
B) 5
C) 4
D) 1
08. Fill the question mark with the suitable code to get the given output.
Output:
[40]
A) g[1][1:]
B) g[0][1]
C) g[:1][1]
D) g[1][:1]
055
Tuples 250 Python Quizzes
056
Sets 250 Python Quizzes
Sets
057
Sets 250 Python Quizzes
04. Fill the question mark with the suitable code to get the given output.
Output:
{'A', 'C'}
A) z.symmetric_difference({'B'})
B) z.intersection_update({'A', 'B', 'C'})
C) z.symmetric_difference_update({'B'})
D) z.difference_update({'A', 'C'})
b = {'A', 'B'}
c = {'A', 'C'}
print(c.issuperset(b))
A) False
B) {'A', 'B'}
C) True
D) {'A', 'C'}
m = {3, 4, 5}
m.discard('3')
print(m)
A) {3, 4, 5}
B) {3}
C) {4, 5}
D) Error
058
Sets 250 Python Quizzes
07. Fill the question mark with the suitable code to get the given output.
Output:
{10, 20, 30, 40, 50}
A) a.add({40, 50})
B) a.update({40, 50})
C) a.intersection({40, 50})
D) a.union({40, 50})
08. Which of the following symbols represents the union operation in a set?
A) ^
B) &
C) |
D) -
09. Fill the question mark with the suitable code to get the given output.
Output:
set()
A) r & s
B) r - s
C) r | s
D) s - r
059
Sets 250 Python Quizzes
060
Dictionaries 250 Python Quizzes
Dictionaries
b = {[10]: 1, [20]: 2}
b.update({[30]: 2})
print(b)
A) {[10]: 1, [20]: 2}
B) {[10]: 1, [20]: 2, [30]: 2}
C) {[10]: 1, [30]: 2}
D) Error
c = {1: 2, 0: 4, 2: 8}
c[1] = 0
print(c)
A) {1: 2, 0: 0, 2: 8}
B) {0: 2, 2: 8}
C) {1: 0, 0: 4, 2: 8}
D) {1: 2, 0: 1, 2: 8}
061
Dictionaries 250 Python Quizzes
04. Fill the question mark with the suitable code to get the given output.
Output:
B
A) d.get('A')
B) d[0]
C) d['B']
D) d.get('C')
A) {1: 23}
B) 66
C) None
D) 89
062
Dictionaries 250 Python Quizzes
08. Fill the question mark with the suitable code to get the given output.
k = {1: 1, 2: 4, 3: 9}
print(?)
Output:
(3, 9)
A) k.pop(3)
B) k.popitem()
C) k.pop()
D) k.popitem(3)
09. Fill the question mark with the suitable code for the output to be 3.
A) m[1][3]
B) m[1]
C) m[2]
D) m[1][2]
063
Dictionaries 250 Python Quizzes
A) iskey()
B) values()
C) keys()
D) items()
064
User Defined Functions 250 Python Quizzes
def a():
print(200, end=' ')
A) 400
B) 200 400
C) 400 200
D) 200
A) **args
B) **kwargs
C) *args
D) *kwargs
def hi(name='Friend'):
print('Hi', name)
hi('Jack')
A) Hi Friend
B) Hi Jack
C) Hi Jack Friend
D) Error
065
User Defined Functions 250 Python Quizzes
04. Which function call prints 10 20 30 as the output for the given function?
05. Fill the question mark with the suitable code to get the given output.
m = lambda x, y: y ** x
print(?)
Output:
9
A) m(x=3, y=2)
B) m(3, 2)
C) m(2, y=3)
D) m(x=2, 3)
r('5', '3')
A) 53
B) 8
C) 35
D) Error
066
User Defined Functions 250 Python Quizzes
def fn(b):
b.append(2)
print(b, end=' ')
a = [1]
print(a, end=' ')
fn(a)
print(a, end=' ')
A) default variable
B) non-local variable
C) local variable
D) global variable
A) 8 4
B) 8
C) 4 8
D) Error
067
User Defined Functions 250 Python Quizzes
def arb(*k):
print(k, end=' ')
arb(1, 7, 9, 5)
A) (1, 7, 9, 5)
B) 1
C) 5
D) [1, 7, 9, 5]
068
Errors and Exceptions 250 Python Quizzes
print(5 + 4 / 0)
A) TypeError
B) ZeroDivisionError
C) ValueError
D) NameError
02. Which block gets executed irrespective of whether an exception occurs or not?
A) except
B) else
C) finally
D) raise
A) StringError
B) FileExistsError
C) KeyError
D) SystemError
print(g)
g = 10
A) ValueError
B) TypeError
C) SyntaxError
D) NameError
069
Errors and Exceptions 250 Python Quizzes
try:
s = int(input())
print(s, end=' ')
except:
print('B', end=' ')
A) B C
B) C
C) A B C
D) A C
A) print(12B)
B) print(list(8, 7, 6))
C) print()
D) print('2' - '3')
for i in range(10):
print(float(i))
A) FloatingPointError
B) TypeError
C) IndentationError
D) SyntaxError
070
Errors and Exceptions 250 Python Quizzes
A) print(a + b)
B) print(int('4.5'))
C) print(z*)
D) print(list(10))
try:
print('5/0', end=' ')
except:
print('Wrong', end=' ')
else:
print('Done', end=' ')
A) 5/0 Done
B) 5/0
C) Wrong
D) Wrong Done
A) ValueError
B) TypeError
C) KeyError
D) IndexError
071
Built-in Functions - 01 250 Python Quizzes
Built-in Functions - 01
01. What is the output of the following code if the input of m is 5.63?
m = input()
print(type(m))
A) <class 'tuple'>
B) <class 'int'>
C) <class 'str'>
D) <class 'float'>
b = (2345)
print(len(b))
A) 4
B) 1
C) 0
D) Error
k = 'D'
print(chr(ord(k) + 30))
A) b
B) D
C) d
D) Error
072
Built-in Functions - 01 250 Python Quizzes
A) True
B) [(), [], {}]
C) False
D) []
r = 'quiz'
print(sorted(r))
a = '5678'
print(sum(a, 4))
A) 30
B) 5682
C) 26
D) Error
073
Built-in Functions - 01 250 Python Quizzes
A) 8
B) 64
C) 1
D) 0
s = 'coding'
x = slice(1, 4)
print(s[x])
A) odi
B) odin
C) din
D) Error
y = [1, 2, 3]
z = [4, 5]
for i in zip(y, z):
print(i, end=' ')
A) (1, 4) (2, 5)
B) (1, 4) (2, 5) (3, 0)
C) (1, 2, 3, 4, 5)
D) (1, 4, 2, 5, 3)
074
Built-in Functions - 01 250 Python Quizzes
A) 01
B) 2
C) 1
D) 03
075
Built-in Functions - 02 250 Python Quizzes
Built-in Functions - 02
r = 154.953
print(round(r, 4))
A) 154.953
B) 154.0000
C) 154.9
D) 154.9530
k = divmod(6, 3)
print(k)
A) (3, 2)
B) (0, 2)
C) (6, 0)
D) (2, 0)
A) 50
B) 70
C) 60
D) 10
076
Built-in Functions - 02 250 Python Quizzes
A) 10
B) 20
C) 40
D) Error
077
Built-in Functions - 02 250 Python Quizzes
z = ('0', 0+0j, 0)
print(any(z))
A) False
B) ('0',)
C) True
D) (0+0j, 0)
s = [10, 20]
for x in enumerate(s, 1):
print(x, end=' ')
078
Built-in Functions - 02 250 Python Quizzes
A) hex()
B) reduce()
C) id()
D) eval()
079
Modules and Packages 250 Python Quizzes
A) from
B) or
C) as
D) else
02. Which statement imports the function named add from the module named calc?
03. Fill the question mark with the suitable code to get 16.0 as the output.
import math
print(?)
A) pow(2, 4)
B) math.pow(2, 4)
C) math(pow(2, 4))
D) sqrt(256)
A) .pym
B) .module
C) .py
D) .mod
080
Modules and Packages 250 Python Quizzes
05. Which of the following modules is used for working with regular expressions?
A) reg
B) regex
C) expr
D) re
06. A package folder must contain the __________ file to be recognized as a package.
A) __main__.py
B) __init__.py
C) __pack__.py
D) __list__.py
07. Which statement imports the module named area from the package named rect?
A) PyPy
B) PyLib
C) PyPkg
D) PyPI
081
Modules and Packages 250 Python Quizzes
10. Which command updates the package named numpy to its latest version?
082
Object Oriented Programming 250 Python Quizzes
01. Which of the following is a blueprint from which objects are created?
A) module
B) class
C) function
D) method
02. What is the syntax for creating an object named c for the given class?
class Car:
pass
A) c = Car()
B) Car c = Car()
C) Car() = c
D) c = Car(c)
A) __main__()
B) __cons__()
C) __self__()
D) __init__()
A) protected
B) public
C) private
D) None of the Above
083
Object Oriented Programming 250 Python Quizzes
A) public
B) protected
C) private
D) None of the Above
06. Which decorator name is used to define a static method within a class?
A) classmethod
B) static
C) staticmethod
D) classdef
class M:
pass
class N(M):
pass
A) Multilevel Inheritance
B) Single Inheritance
C) Hierarchical Inheritance
D) Multiple Inheritance
A) main class
B) derived class
C) base class
D) abstract class
084
Object Oriented Programming 250 Python Quizzes
class A:
pass
class B:
pass
A) Multilevel Inheritance
B) Single Inheritance
C) Hierarchical Inheritance
D) Multiple Inheritance
class R(T):
pass
class S(R):
pass
class T(S):
pass
A) Multiple Inheritance
B) Hierarchical Inheritance
C) Multilevel Inheritance
D) Error
085
File Handling 250 Python Quizzes
File Handling
01. Which statement opens the file named sum.txt for writing?
A) f = open('w', 'sum.txt')
B) f = open('a', 'sum.txt')
C) f = open('sum.txt', 'w')
D) f = open('sum.txt', 'r')
02. Which error is displayed when a file that doesn't exist is opened in read mode?
A) FileNotExistsError
B) FileExistsError
C) FileError
D) FileNotFoundError
A) readable()
B) append()
C) flush()
D) truncate()
A) exit()
B) close()
C) closefile()
D) end()
086
File Handling 250 Python Quizzes
A) x
B) a
C) r
D) c
06. Which file mode displays an error when a file that already exists is opened?
A) Create
B) Read
C) Write
D) Append
07. Which statement reads the given file completely up to the end as a string?
f = open('a.txt')
A) f.readline()
B) f.seek()
C) f.read()
D) f.readlines()
A) assert
B) yield
C) with
D) import
087
File Handling 250 Python Quizzes
09. Which file mode places the file pointer at the end of the file?
A) Create
B) Write
C) Read
D) Append
A) tell()
B) set()
C) position()
D) seek()
088
Correct Answers 250 Python Quizzes
Correct Answers
Introduction to Python
01. (C) Guido van Rossum
02. (D) .py
03. (B) 1991
04. (C) Both Compiled and Interpreted
05. (B) 35
06. (B) Preferred Installer Program
07. (A) #
08. (B) sqrt()
09. (D) All of the Above
10. (C) IDLE
089
Correct Answers 250 Python Quizzes
Data Types - 01
01. (A) dict
02. (A) ('A')
03. (C) {6, [2, 3], 5}
04. (B) ['0']
05. (C) {1: 'C', 2: 'B'}
06. (D) <class 'tuple'>
07. (D) 0.95e-1
08. (B) Integer to Float
09. (B) 8
10. (B) False
Data Types - 02
01. (B) Dictionary
02. (B) set()
03. (D) Error
04. (C) List to Integer
05. (C) 6+0j
06. (C) ['1', '2', '3']
07. (C) 4
08. (D) (0)
090
Correct Answers 250 Python Quizzes
Decision-Making Statements
01. (B) 4
02. (D) 9 7
03. (D) Error
04. (B) elif
05. (B) 3
06. (A) 6
07. (A) Underscore (_)
08. (A) 1 2
09. (C) r % 2 == 1
10. (A) Bronze 13
Looping Statements
01. (D) 5-6-7-8-9-
02. (A) 15&11&
03. (B) 3
04. (D) 0
05. (D) range(7, 3, -2)
06. (C) Blank Output
07. (B) 0 1 2
08. (A) 10 20 30
091
Correct Answers 250 Python Quizzes
Strings - 01
01. (D) upper()
02. (D) print('Z' * 3)
03. (B) s i
04. (C) replace()
05. (A) net
06. (D) ice coffee
07. (B) print('353533535'[::-4])
08. (C) print('apple'[-4:-2])
09. (C) pyeyaycye
10. (B) o
Strings - 02
01. (D) e
02. (C) ['h', 'rdw', 're']
03. (B) ploglammers
04. (B) print('\\\\')
05. (D) 6
06. (D) Error
07. (A) j[-3:2:-1]
08. (D) 2
09. (B) Python Quiz
10. (C) gol
Strings - 03
01. (C) ['or', 'gin']
02. (D) Blank Output
03. (A) True
04. (C) remove()
05. (A) download
06. (B) 2
07. (C) chip\'s question
08. (C) 0650
092
Correct Answers 250 Python Quizzes
09. (B) ac
10. (A) ('devel', 'o', 'per')
Lists - 01
01. (D) ['A', 'B']
02. (A) [1, 2, 3, 3, 4]
03. (B) [5, 6, 8, 3, 4]
04. (C) [2, 7, 6, [8, 9]]
05. (D) Error
06. (C) [30, 40, 30, 40]
07. (B) [13, 14, 15, 16]
08. (D) Error
09. (A) [92, 80, 66, 43, 21]
10. (B) List Comprehension
Lists - 02
01. (A) h[2][0]
02. (A) [1, 3, 2, 5]
03. (D) [76, 24] [76]
04. (D) [15, 54, 33]
05. (A) 2
06. (B) 4
07. (A) i.append([40, 50])
08. (C) d.pop()
09. (B) [20]
10. (C) pop()
Lists - 03
01. (B) None
02. (C) ['3', '4', '5', '6']
03. (B) [45, 32] [45, 32]
04. (D) ['B', 'C', 'a', 'b']
05. (B) [[1, 2], [1, 2]]
06. (B) c[-3] = [24]
07. (B) []
08. (D) 3
093
Correct Answers 250 Python Quizzes
Tuples
01. (B) ()
02. (D) Error
03. (A) [2, 3, 4]
04. (D) n.index(3, 2)
05. (C) (4, 4, 4, 4)
06. (C) 1
07. (A) 3
08. (D) g[1][:1]
09. (A) (10, 20, 30, 10)
10. (B) Tuples are Mutable
Sets
01. (D) {'7', 5, '6', '5'}
02. (D) {'D', 'E'}
03. (C) {11, 33}
04. (C) z.symmetric_difference_update({'B'})
05. (A) False
06. (A) {3, 4, 5}
07. (B) a.update({40, 50})
08. (C) |
09. (A) r & s
10. (B) None
Dictionaries
01. (A) {1: 10, 2: 40, 3: 30}
02. (D) Error
03. (C) {1: 0, 0: 4, 2: 8}
04. (D) d.get('C')
05. (B) 66
06. (A) {4: 12, 2: 48, 3: 36, 1: 24}
07. (C) {1: 10, 2: 20, 3: 30}
08. (B) k.popitem()
094
Correct Answers 250 Python Quizzes
Built-in Functions - 01
01. (C) <class 'str'>
02. (D) Error
03. (A) b
04. (C) False
05. (B) ['i', 'q', 'u', 'z']
06. (D) Error
07. (C) 1
08. (A) odi
095
Correct Answers 250 Python Quizzes
Built-in Functions - 02
01. (A) 154.953
02. (D) (2, 0)
03. (B) 70
04. (D) Error
05. (C) [91, 83, 55]
06. (A) [32, 45, 84, 95]
07. (C) True
08. (D) [65, 66, 67]
09. (B) (1, 10) (2, 20)
10. (B) reduce()
096
Correct Answers 250 Python Quizzes
File Handling
01. (C) f = open('sum.txt', 'w')
02. (D) FileNotFoundError
03. (B) append()
04. (B) close()
05. (A) x
06. (A) Create
07. (C) f.read()
08. (C) with
09. (D) Append
10. (D) seek()
***************
097
Empty Pages 250 Python Quizzes
098
Empty Pages 250 Python Quizzes
099