Question bank
Pick an answer to see if you're right — with an explanation.
All topicsPythonSQL / MySQLData ScienceNumPyPandasMatplotlibMachine LearningDeep LearningArtificial IntelligenceLarge Language ModelsDjangoAPIsGit & GitHubPower BIExcelStatistics
PythonEasy
What is the output of `print(type([]))`?
a<class 'tuple'>
b<class 'dict'>
c<class 'list'>
d<class 'array'>
Explanation: Square brackets create a list.
PythonEasy
What does `sorted([3, 1, 2])` return?
aNone
b[1, 2, 3]
c(1, 2, 3)
dIt sorts in place
Explanation: `sorted()` returns a new list; `list.sort()` is the in-place version that returns None.
PythonEasy
Which keyword defines a function?
afunc
bfunction
clambda
ddef
Explanation: Functions are defined with `def`; `lambda` creates anonymous functions.
PythonEasy
Which module provides `Counter` and `defaultdict`?
aitertools
bfunctools
ccollections
dstatistics
Explanation: Both live in the `collections` module of the standard library.
PythonEasy
What does this print?
x = [1, 2, 3]
print(x[-1])
a3
b1
cError
d-1
Explanation: Negative indexes count from the end.
PythonEasy
Which keyword turns a function into a generator?
areturn
basync
clambda
dyield
Explanation: Any function body containing `yield` returns a generator object when called.
PythonMedium
Which type is immutable?
alist
btuple
cdict
dset
Explanation: Tuples cannot be changed after creation.
PythonEasy
With `from pathlib import Path`, what is `Path('data/sales.csv').stem`?
asales
bsales.csv
c.csv
ddata
Explanation: `.stem` is the file name without its suffix.
PythonEasy
What is `3 // 2`?
a1.5
b2
c0
d1
Explanation: `//` is floor division.
PythonMedium
What does this print?
import re
print(re.findall(r'\d+', 'Order 12 costs 450 rupees'))
a['12 450']
b[12, 450]
c['12', '450']
d['1', '2', '4', '5', '0']
Explanation: `findall` returns every match as a string; `\d+` matches runs of digits.
PythonMedium
What does `len({'a': 1, 'b': 2})` return?
a2
b1
c4
dError
Explanation: len of a dict counts keys.
PythonMedium
Why should CSV files be opened with `newline=''` when using the csv module?
aIt lets the csv module handle line endings correctly and avoids blank rows on Windows
bIt removes the header row
cIt makes reading faster by skipping empty lines
dIt is required for UTF-8
Explanation: The csv module does its own newline handling; `newline=''` stops Python translating line endings underneath it.
PythonMedium
Output of the code?
s = 'BeeProton'
print(s[3:6])
aePr
bPro
cProt
deeP
Explanation: Slicing is start-inclusive, end-exclusive: indexes 3,4,5.
PythonMedium
What is printed?
gen = (x * 2 for x in range(3))
print(sum(gen), sum(gen))
a6 6
b6 0
c0 6
dTypeError
Explanation: A generator is exhausted after one pass, so the second `sum` sees no items.
PythonMedium
How do you handle an exception?
acatch / throw
bif / error
ctry / except
dhandle / rescue
Explanation: Python uses try/except blocks.