Related: Design Patterns, Async, Metaprogramming, Security


Q1. What pattern ensures a class has only one instance?

  • A) Factory
  • B) Singleton ✓
  • C) Observer
  • D) Strategy

Q2. What does asyncio.gather() do?

  • A) Collects garbage
  • B) Runs coroutines concurrently and collects results ✓
  • C) Creates a thread pool
  • D) Imports async modules

Q3. What is a Python descriptor?

  • A) A file description
  • B) An object defining __get__, __set__, or __delete__ to control attribute access ✓
  • C) A type hint
  • D) A docstring format

Q4. Which tool profiles Python code at the function level?

  • A) black
  • B) cProfile ✓
  • C) mypy
  • D) pytest

Q5. What does @lru_cache do?

  • A) Deletes old files
  • B) Memoizes function results ✓
  • C) Limits recursion
  • D) Caches imports

Q6. What is the correct way to prevent SQL injection?

  • A) Escape strings manually
  • B) Parameterized queries ✓
  • C) Use NoSQL only
  • D) Disable SQL logging

Q7. What is a metaclass in Python?

  • A) A metadata file
  • B) A class that controls how other classes are created ✓
  • C) A parent class
  • D) A deprecated feature

Q8. Docker containers vs virtual machines?

  • A) Containers include full OS
  • B) Containers share the host OS kernel — lighter and faster ✓
  • C) VMs are always faster
  • D) No difference

Q9. What is the purpose of __slots__?

  • A) Enable threading
  • B) Reduce memory by preventing __dict__ creation ✓
  • C) Add methods dynamically
  • D) Enable async

Q10. What does the Strategy pattern do?

  • A) Creates objects
  • B) Defines interchangeable algorithms behind a common interface ✓
  • C) Notifies observers
  • D) Ensures single instance

Scoring: 8+ = expert-ready. Review missed topics in Stage 3 Expert chapters.

Also see: Advanced Testing | GraphQL | Kafka

Next: Interview Prep | Coding Patterns