Python / Async Interview Questions 2026
32 Python / Async interview questions from Amazon, General, TCS, Google, Uber, Microsoft and more. Real questions from Technical, System Design, and HR rounds.
All Python / Async Questions
Explain the difference between __repr__ and __str__. When is each called? Write a class where they return different things.
You're using Python multiprocessing and processes need to share a large dictionary (2GB) read-only. Creating copies per process uses 20GB total. How do you share memory efficiently?
What are Python generators and when would you use them over lists? Implement a Fibonacci generator.
Your Python application has a function that should cache results but the @functools.lru_cache decorator is causing memory issues. Objects cached are large DataFrames. How do you implement a size-bounded cache?
Your Python service handles JSON data from multiple sources. Some send {'amount': '100.50'}, others send {'amount': 100.50}. Your code crashes intermittently when doing arithmetic. Fix this robustly.
Your Python service deployed in Docker shows 10% more memory usage after each deployment with no code changes. What do you investigate?
You're building a data pipeline in Python that processes streaming data. The pipeline has 5 stages. How do you ensure a failure in stage 3 doesn't lose data already processed by stages 1 and 2?
Explain Python metaclasses. When would you actually use one in production code?
What is the difference between @staticmethod and @classmethod in Python? Give use cases for each.
A Django application using ORM makes 1 query per user in a list view. When the list has 500 users, the page makes 501 queries (1 for user list + 1 per user for their profile). Fix this with minimal code changes.
Your Celery worker is processing tasks but tasks take 10 minutes each and the beat scheduler keeps adding duplicates because the first hasn't finished. Fix this.
Explain Python's garbage collector alongside reference counting. When does reference counting fail?
Explain Python's GIL. You have CPU-bound code that you parallelized with threading. It's not faster. Why? How do you actually make it faster?
You have a Python function that runs in 30 seconds. A profiler shows 90% of time is in one NumPy operation on a 10,000 x 10,000 matrix. How do you make it faster?
Your Python scraper fails with 'SSL: CERTIFICATE_VERIFY_FAILED'. A colleague suggests verify=False. Why is that dangerous and what's the correct fix?
You have a Python script that processes 1 million records from a database. It loads all records into a list, processes each, then writes results. Memory usage hits 16GB and the OS kills it. Fix this without changing the database schema.
Explain the difference between deepcopy and shallow copy in Python. Give a scenario where using shallow copy caused a bug.
Implement a Python decorator that retries a function up to N times with exponential backoff on specific exception types.
Your Python FastAPI service handles 1000 requests/second. Adding one blocking I/O call (requests.get()) drops throughput to 50 requests/second. Why and how do you fix it without rewriting the service?
Your Python service runs in Docker. On developer machines (Mac M1) it works fine. In production (Linux x86) it crashes with a C extension error. What's happening and how do you fix it?
Your Python code processes a 10GB JSON file. json.load() fails with MemoryError. How do you handle it?
Explain Python's descriptor protocol. How does @property use it? Write a descriptor that validates a positive integer.
Your Python script takes 10 minutes to process 1 million CSV rows. Profile shows 80% time is in a string parsing function. Rewrite this function for maximum performance.
What is Python's __slots__ and when would you use it? What are the trade-offs?
Your Django REST API has an endpoint that calls 3 external services sequentially, each taking ~500ms. Total response time is ~1.5 seconds. How do you parallelize these calls?
Your Flask API crashes with 'RuntimeError: Working outside of application context.' When does this happen?
Write a Python context manager for a database transaction that commits on success and rolls back on exception.
You have a 50GB CSV file and only 8GB of RAM. Walk through how you would compute the average of one column using pandas without crashing the process.
You need to find all available drivers within a 3km radius of a rider efficiently, with millions of driver location updates per second. What indexing structure would you use and why not a naive distance calculation over all drivers?
Explain how Python's dictionary achieves average O(1) lookup. What happens internally when two keys hash to the same bucket?
What is the difference between .loc[] and .iloc[] in pandas? Give an example where using the wrong one silently returns the wrong row.
Write a Python decorator @timed that prints how long a function took to execute, and explain how functools.wraps prevents it from breaking introspection.
Practice these questions with AI feedback
Get instant grading on your answers, identify your weak areas, and generate a personalised 14-day study plan — all free.
Build my study plan →