Back to Intermediate Python & Clean Code
Final Assessment

Intermediate Python & Clean Code Final Assessment

Test your mastery across dict/set comprehensions, collections, yield generators, decorators, functools/itertools, dataclasses, dunder methods, context managers, pathlib, regex, logging, asyncio, and pytest fixtures/mocking. Score 70% or higher to earn your certificate.

Answered 0 of 15 questionsPass mark: 70%
Question 1

Question 1 of 15

What does first, *middle, last = [10, 20, 30, 40] assign to middle?

Question 2

Question 2 of 15

Why is sum(x * x for x in range(1_000_000)) preferred over sum([x * x for x in range(1_000_000)])?

Question 3

Question 3 of 15

What does deque([1, 2, 3], maxlen=3).append(4) leave inside the deque?

Question 4

Question 4 of 15

What happens if you iterate over a yield generator a second time without recreating it?

Question 5

Question 5 of 15

Why should custom Python decorators apply @functools.wraps(func) to the inner wrapper function?

Question 6

Question 6 of 15

What important requirement must you remember before calling itertools.groupby(items, key=...)?

Question 7

Question 7 of 15

In a @dataclass, how do you safely give each instance its own empty list attribute?

Question 8

Question 8 of 15

If a class defines __repr__ but does not define __str__, what does print(obj) output?

Question 9

Question 9 of 15

Inside a @contextlib.contextmanager generator, why must yield be placed inside a try: ... finally: block?

Question 10

Question 10 of 15

With pathlib.Path, how do you recursively find all .py files inside src/ and its subfolders?

Question 11

Question 11 of 15

What is the key difference between re.match(pattern, text) and re.search(pattern, text)?

Question 12

Question 12 of 15

Why is datetime.now(timezone.utc) recommended over naive datetime.now() in backend services?

Question 13

Question 13 of 15

Which concurrency approach bypasses Python's GIL to run heavy CPU-bound math across multiple CPU cores?

Question 14

Question 14 of 15

In pytest, what is @pytest.mark.parametrize used for?

Question 15

Question 15 of 15

Why do Python developers write logger.debug('User %s failed', user_id) instead of an f-string inside logger calls?

Answer 15 more questions to submit.