Describe a time you had to debug something difficult in Python. How did you approach it?
Describe a method, because the interviewer is checking whether you debug systematically or by guessing.
- Reproduce it reliably first. Most of the effort in a hard bug goes here — a failure that only happens with production data volume, or only under concurrency, or only on the third run.
- Narrow it down. Bisect the code path, or use
git bisectif it used to work. Add assertions where you believe the state is still correct and move them later until one fails. - The tools you reached for.
pdborbreakpoint()for stepping,loggingat DEBUG rather than scattered prints,tracebackfor the full chain,cProfileif it was slow, andtracemallocif memory was the issue. - The root cause. Good stories: a mutable default argument shared across calls, a shallow copy where a deep copy was needed, an exception silently swallowed by a bare
except, or a floating-point comparison.
Note: Finish with the regression test you added. A bug fixed without a test is a bug scheduled to return.





