download

Python Interview Questions

Practice sets and dicts, generators, closures, decorators, asyncio cancellation, concurrency, and context managers with free Python interview questions. Each exercise includes hints and a checked answer.

Python14 questionsFree · No sign-in

Practice questions

  1. Remove duplicates from a list but keep the original order · sets and dicts · 10 min
  2. Why did changing a copied dict also change the original? · copying · 10 min
  3. What happens when you iterate over a generator twice? · generators · 12 min
  4. Why do all these lambdas return the same number? · closures · 8 min
  5. What does a decorator do, and why use functools.wraps? · decorators · 10 min
  6. In what order do try, except, else and finally run? · exceptions · 8 min
  7. Threads, processes or asyncio: which fits each of these jobs? · concurrency · 10 min
  8. Your mock.patch has no effect. Where should you patch? · mocking · 12 min
  9. How do you pass user input to SQL safely from Python? · databases · 10 min
  10. What does mean(axis=0) return, and why isn't reshape a transpose? · NumPy · 8 min
  11. Why does a default list keep items from earlier calls? · Function defaults · 8 min
  12. Why did this with block leak a lock and hide an error? · Context managers · 10 min
  13. Why did cancelling this asyncio task skip cleanup or break timeout? · Asyncio cancellation · 12 min
  14. Why did a lazy iterator fail or read mutated data later? · Lazy iterators · 10 min

How to practice

Predict the result or explain what you would change before opening the hints. Then compare your reasoning with the answer and try the follow-up question.

Open the interactive Python deck →