What this Python truthiness interview question tests
This is a medium-difficulty question that probes your working knowledge of Python's truthiness rules and type coercion. It's the kind of question trading firms ask to verify that you understand Python's implicit boolean conversions—a common source of bugs in production code, especially when data flows through conditionals or boolean operations without explicit casting.
To answer correctly, you need to know which built-in types and values Python treats as truthy or falsy in a boolean context, how the language evaluates compound boolean expressions, and what output statements actually produce. The question rewards careful reading of the code path over guessing; interviewers use it to distinguish between candidates who know Python deeply and those who only use it casually.
- Truthiness of empty containers, None, and numeric zero
- Short-circuit evaluation of
and and or operators - Return values of boolean expressions
- Print statement behaviour and type coercion