← Back to videos

Junior Python interview: decorators, lambdas and code that wasn’t supposed to work

Interview timeline Click any block to jump

Interview breakdown

Interviewer verdict
Passed with caveats Level: Junior (with foundational theory gaps)

Borderline pass ('more yes than no'): despite noticeable theoretical errors and self-contradictions around decorator execution timing, callable objects, and side effects, the candidate compensated with thoughtful analytical reasoning and successfully worked through an unfamiliar nested lambda-decorator puzzle without giving up.

Candidate: Alexander
Target role: Junior Python Developer

36 y/o · non-IT background, self-studying Python daily for the past 11 months · first technical interview

Answers accuracy 14 total
61% score
Theory
4/12 correct · 54%
Live coding
2/2 correct · 100%
Practical task
Solved

Parenthesized nested lambda decorator with int() tuple indexing

Facing @(lambda f: lambda x: (f(x), f(x) * 100)[int()]) above def square(x): return x ** 2 and print(square(3)) for the first time, the candidate mapped the outer and inner lambdas to decorator and wrapper, evaluated the tuple (9, 900), deduced that int() with no arguments returns index 0, and correctly predicted the output 9.

Topics covered Click a topic to filter questions

Candidate strengths

  • + Thoughtful, analytical reasoning rather than reciting memorized textbook definitions
  • + Resilience on unfamiliar code syntax: overcame initial surprise and deduced the exact output step by step
  • + Solid grasp of basic pure functions, anonymous lambdas, map/filter, and wrapper functions inside decorators
  • + Strong self-discipline (11 months of daily study) and constructive reception of feedback

Areas to improve

  • → Keep track of earlier statements during a discussion to avoid self-contradictions when a topic is revisited from another angle
  • → Distinguish decorator evaluation at definition time from wrapper execution at call time
  • → Understand Python's callable protocol (__call__) across functions, methods, classes, and class instances
  • → Review zero-argument built-in type constructors (int() == 0) and relaxed decorator grammar (PEP 614)

Questions in this interview

14 / 14
01 ▶ 04:31
What is a function in programming, and what are the core ideas of functional programming?
Theory Functions, scopes & closures
?
Candidate's answer

Correctly defined a function as a named reusable code block, but reduced functional programming merely to organizing code with functions.

Key takeaway

Functional programming centers on pure functions, immutable data, avoiding shared mutable state, and composing first-class functions.

Open moment on YouTube ↗
#01
02 ▶ 07:36
What is a pure function and what counts as a side effect?
Theory Functions, scopes & closures
?
Candidate's answer

Accurately stated both criteria: deterministic return values for identical inputs and no observable side effects such as print() output or mutating globals.

Key takeaway

A pure function depends solely on its inputs and causes no external state mutations or I/O, making it trivial to test, parallelize, and memoize.

Open moment on YouTube ↗
#02
03 ▶ 13:26
What is a lambda function in Python, where is it used, and how does built-in map() work?
Theory Functions, scopes & closures
?
Candidate's answer

Explained that lambda creates an inline anonymous function and accurately described map() as taking a function and an iterable and returning a lazy iterator of transformed items.

Key takeaway

A lambda body is restricted to a single expression, and map() in Python 3 returns a lazy iterator that computes values on demand.

Open moment on YouTube ↗
#03
04 ▶ 17:37
Are lambda functions, map(), and filter() always pure functions?
Theory Functions, scopes & closures
?
Candidate's answer

Assumed lambda, map, and filter are inherently pure because they accept inputs and return outputs.

Key takeaway

Lambda syntax and map/filter do not enforce purity: a lambda can still perform I/O or mutate state (e.g., print or list.append), and iterators themselves have stateful consumption.

Open moment on YouTube ↗
#04
05 ▶ 18:10
What is a higher-order function and what examples exist in Python?
Theory Functions, scopes & closures
?
Candidate's answer

Defined it as a function that accepts another function as an argument or returns a function, citing map(), filter(), and custom wrappers.

Key takeaway

Standard Python higher-order functions include map, filter, sorted(key=...), functools.reduce, and function decorators.

Open moment on YouTube ↗
#05
06 ▶ 21:26
What is the Decorator pattern conceptually, and how does a decorator work in Python?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Explained that a decorator extends behavior without modifying the original object, implemented in Python by taking a callable and returning a wrapped callable.

Key takeaway

@deco above def fn(): ... is syntactic sugar for fn = deco(fn), rebinding the name to whatever object deco returns.

Open moment on YouTube ↗
#06
07 ▶ 24:47
What entities can be decorated in Python: functions, methods, classes?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Initially named functions, methods, and classes accurately, but later backtracked under questioning and became unsure whether classes themselves can be decorated.

Key takeaway

Python's @decorator syntax applies to functions, coroutines, methods, and class definitions alike (for example, @dataclass).

Open moment on YouTube ↗
#07
08 ▶ 26:40
What can act as a decorator itself: a function, a class, a class instance, or a method?
Theory OOP, classes & dunder methods
?
Candidate's answer

Correctly described function decorators and class decorators implementing __call__, but rejected class instances and methods as valid decorators.

Key takeaway

Any callable object can serve as a decorator in Python: a function, lambda, class, bound method (like @app.get('/')), or class instance defining __call__.

Open moment on YouTube ↗
#08
09 ▶ 37:13
When does the decorator itself execute: when the decorated function is defined or when it is called?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Despite noting that a new function object is returned at definition time, insisted that the decorator executes when the decorated function is called.

Key takeaway

The decorator itself runs immediately at function definition/import time, whereas the inner wrapper function runs later each time the decorated function is called.

Open moment on YouTube ↗
#09
10 ▶ 40:17
Must a decorator always call the original decorated function?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Hesitated at length thinking calling the original function is essential, before concluding after a caching hint that skipping the call is technically valid.

Key takeaway

A decorator does not have to invoke the wrapped function on every call (e.g., cache hits, auth guards, mocks) or may simply register it and return it unchanged.

Open moment on YouTube ↗
#10
11 ▶ 46:55
Can a decorator invoke the original function multiple times, and what risks does that carry?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Gave a great retry-on-connection-failure example, but mistakenly assumed repeated calls cannot cause side-effect issues if the arguments stay the same.

Key takeaway

Retry decorators call the wrapped function multiple times, which is only safe for idempotent operations; non-idempotent functions risk duplicate writes or charges.

Open moment on YouTube ↗
#11
12 ▶ 50:00
How can you extend the behavior of a function or class without using decorators?
Theory OOP, classes & dunder methods
?
Candidate's answer

Could not recall ways to wrap functions without decorators and lost track of his earlier statements when comparing class decorators to inheritance.

Key takeaway

Behavior can be extended without @ syntax via explicit wrapper functions, composition/delegation, functools.partial, or class inheritance and mixins.

Open moment on YouTube ↗
#12
13 ▶ 55:01
Is @(lambda f: lambda x: (f(x), f(x) * 100)[int()]) above def square(x): return x ** 2 valid Python syntax?
Live coding Decorators, iterators, generators & context managers
?
Candidate's answer

Initially surprised by parentheses and an inline lambda after @, he reasoned from first principles that a lambda is a valid callable decorator whose inner lambda acts as the wrapper.

Key takeaway

Since Python 3.9 (PEP 614), any valid expression evaluating to a callable — including a parenthesized lambda — is allowed after @.

Open moment on YouTube ↗
#13
14 ▶ 01:03:35
What does calling int() with no arguments return, and what will print(square(3)) output?
Live coding Data types, numbers & memory
?
Candidate's answer

Computed the tuple (9, 900) for x = 3, deduced that int() indexes the tuple and returns 0 when called without arguments, and correctly predicted 9.

Key takeaway

Zero-argument calls to built-in type constructors return their default falsy value: int() -> 0, float() -> 0.0, str() -> '', list() -> [], bool() -> False.

Open moment on YouTube ↗
#14
Original video description & timecodes

A mock technical interview for the role of Junior Python Developer. We discuss functions, the functional approach, pure functions, `map`, `filter`, higher-order functions, decorators and an unexpected code example involving `lambda`. At the end, there’s detailed feedback: what went well, where there were inconsistencies, and which topics you should brush up on before the actual interview.

Timestamps:
00:00 — Start
00:48 — Introductions
04:31 — What is a function?
05:08 — Functional programming
07:36 — Pure functions and side effects
13:26 — Lambda functions, `map` and `filter`
18:10 — Higher-order functions
21:26 — Decorators: the concept and implementation in Python
24:47 — What can be decorated
37:13 — When a decorator is executed
40:17 — Can a decorator avoid calling the original function?
50:00 — Alternatives to decorators and inheritance
54:47 — Coding challenge: a lambda decorator
01:14:57 — Candidate’s feedback
01:16:46 — Analysis of mistakes and strengths
01:28:13 — Final assessment of the interview