Explain Core Python Runtime and Language Concepts
Company: Squarepoint
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: HR Screen
# Explain Core Python Runtime and Language Concepts
Answer the following Python questions as if you were reviewing production code. Use small examples where they make behavior clearer, and distinguish language guarantees from implementation details.
### Clarifying Questions to Ask
- Which Python implementation and version should be assumed?
- Are the concurrency examples CPU-bound or I/O-bound?
- Should examples emphasize API design, memory use, or raw execution speed?
### Solving Hints
For each concept, explain the problem it solves, the mechanism it uses, and one failure mode caused by using it carelessly.
### Part 1: Generators
Explain how a generator differs from returning a fully materialized collection. Discuss laziness, state, exhaustion, memory use, and error timing.
#### What This Part Should Cover
- Iteration protocol, lazy evaluation, one-pass behavior, and appropriate use cases.
### Part 2: Decorators
Explain what a function decorator receives and returns, how closures are involved, and why preserving wrapped-function metadata matters.
#### What This Part Should Cover
- Decoration time versus call time, wrapper signatures, metadata, and parameterized decorators.
### Part 3: Threads and Processes
Compare Python threads and processes for CPU-bound work and I/O-bound work. Include communication, isolation, failure, and lifecycle costs.
#### What This Part Should Cover
- Concurrency versus parallelism, interpreter constraints, serialization, and shared-state risks.
### Part 4: Mutability
Explain mutable and immutable objects, aliasing, hashability, and the mutable-default-argument trap.
#### What This Part Should Cover
- Object identity versus rebinding, safe dictionary keys, and defensive API choices.
### Part 5: Context Managers
Explain the context-manager protocol and how it guarantees cleanup when the body raises an exception.
#### What This Part Should Cover
- `__enter__`, `__exit__`, exception suppression, and `try/finally` equivalence.
### What a Strong Answer Covers
- Correct mental models rather than memorized definitions.
- Concrete trade-offs and edge cases for all five parts.
- Awareness that behavior can differ between Python implementations.
- Examples that demonstrate ownership, cleanup, or concurrency hazards without hiding them behind library calls.
### Follow-up Questions
- Why can a generator delay an exception until iteration?
- How would you make a decorator work on both synchronous and asynchronous functions?
- When would shared memory between processes be justified?
Quick Answer: Review core Python concepts through a production-engineering lens: generators, decorators, threads versus processes, mutability, and context managers. Explain guarantees, implementation details, trade-offs, and common failure modes with focused examples.