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
PythonMedium
Which `json.dumps` argument keeps Hindi text readable instead of `\u` escapes?
aindent=2
bsort_keys=True
cdefault=str
densure_ascii=False
Explanation: By default non-ASCII characters are escaped; `ensure_ascii=False` writes them as-is.
PythonHard
What does this print?
a = [[1, 2], [3, 4]]
b = a.copy()
b[0].append(99)
print(a[0])
a[1, 2]
b[1, 2, 99]
c[[1, 2, 99], [3, 4]]
dAttributeError
Explanation: `list.copy()` is a shallow copy, so both lists still point at the same inner lists; use `copy.deepcopy` for nested data.
PythonHard
Why use `functools.wraps` inside a decorator?
aIt copies the wrapped function's name, docstring and metadata onto the wrapper
bIt makes the wrapper run faster
cIt caches return values
dIt is required for decorators to accept arguments
Explanation: Without it, the decorated function reports the wrapper's name and loses its docstring, confusing debugging and tools.
PythonHard
What is printed?
fs = [lambda: i for i in range(3)]
print(fs[0]())
a2
b0
c1
dTypeError
Explanation: All three lambdas share the same `i`, which is 2 once the comprehension finishes; capture it with a default argument such as `lambda i=i: i`.
PythonHard
What does this print?
def add(item, bucket=[]):
bucket.append(item)
return bucket
add(1)
print(add(2))
a[2]
b[1, 2]
c[1]
d[]
Explanation: Default values are evaluated once, so the same list is shared between calls; use `None` as the default instead.