Question bank

Pick an answer to see if you're right — with an explanation.

PythonEasy
What is the output of `print(type([]))`?
a<class 'tuple'>
b<class 'dict'>
c<class 'list'>
d<class 'array'>
PythonEasy
What does `sorted([3, 1, 2])` return?
aNone
b[1, 2, 3]
c(1, 2, 3)
dIt sorts in place
PythonEasy
Which keyword defines a function?
afunc
bfunction
clambda
ddef
PythonEasy
Which module provides `Counter` and `defaultdict`?
aitertools
bfunctools
ccollections
dstatistics
PythonEasy
What does this print?
x = [1, 2, 3]
print(x[-1])
a3
b1
cError
d-1
PythonEasy
Which keyword turns a function into a generator?
areturn
basync
clambda
dyield
PythonMedium
Which type is immutable?
alist
btuple
cdict
dset
PythonEasy
With `from pathlib import Path`, what is `Path('data/sales.csv').stem`?
asales
bsales.csv
c.csv
ddata
PythonEasy
What is `3 // 2`?
a1.5
b2
c0
d1
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']
PythonMedium
What does `len({'a': 1, 'b': 2})` return?
a2
b1
c4
dError
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
PythonMedium
Output of the code?
s = 'BeeProton'
print(s[3:6])
aePr
bPro
cProt
deeP
PythonMedium
What is printed?
gen = (x * 2 for x in range(3))
print(sum(gen), sum(gen))
a6 6
b6 0
c0 6
dTypeError
PythonMedium
How do you handle an exception?
acatch / throw
bif / error
ctry / except
dhandle / rescue