Top 10 Python Interview Questions 2025
Real questions asked at Google, Amazon, Flipkart, Paytm, and startups. From GIL to async — everything for 2025-2026 interviews.
Core Python (Q1-Q10)
Q1: What is the GIL?
The Global Interpreter Lock allows only one thread to execute Python bytecode at a time — even on multi-core systems. Use multiprocessing for CPU parallelism, asyncio for I/O concurrency.
Q2: Mutable vs Immutable types?
Immutable: int, float, str, tuple, frozenset. Mutable: list, dict, set. Never use mutable default arguments — they are shared across all calls.
def append(item, lst=None): # GOOD
if lst is None: lst = []
lst.append(item)
return lst
Q3: What are *args and **kwargs?
def fn(*args, **kwargs):
print(args) # tuple: (1, 2, 3)
print(kwargs) # dict: {'name': 'Rahul'}
Q4: How does Python garbage collection work?
Primary: reference counting — freed when count hits 0. Secondary: cyclic garbage collector handles reference cycles (A references B references A). Memory allocator uses pools for small objects.
Q5: What is a decorator?
A function that wraps another function to add behavior. @decorator is syntactic sugar for func = decorator(func). Uses: logging, caching, auth, timing.
Q6: Difference between list, tuple, set, dict?
list: ordered, mutable, allows duplicates. tuple: ordered, immutable, allows duplicates (hashable). set: unordered, mutable, no duplicates, O(1) lookup. dict: key-value mapping, ordered (Python 3.7+), O(1) key lookup.
Q7: What is a generator?
A function using yield that produces values lazily — one at a time without building the full list. Uses constant memory regardless of sequence size. Great for large datasets and infinite sequences.
Q8: shallow copy vs deep copy?
import copy
original = {'a': [1, 2, 3]}
shallow = copy.copy(original) # same inner list
deep = copy.deepcopy(original) # independent copy
original['a'].append(4)
print(shallow['a']) # [1,2,3,4] — shared!
print(deep['a']) # [1,2,3] — independent
Q9: What is asyncio?
Single-thread cooperative concurrency via event loop and coroutines. async def defines coroutines; await suspends until completion. Better than threads for I/O-bound tasks (HTTP requests, DB queries) — can handle thousands concurrently.
Q10: Reverse words in a string.
def reverse_words(s: str) -> str:
return ' '.join(s.split()[::-1])
print(reverse_words("Hello World")) # "World Hello"
Comments (0)
No comments yet. Be the first!
Leave a Comment