Python Interview Handbook (300+ Questions & Answers)

Python Interview Handbook

Complete Preparation Guide for USA Jobs

Target Roles

  • Python Developer
  • Software Engineer
  • Senior Software Engineer
  • AWS Data Engineer
  • Cloud Engineer
  • Solutions Architect
  • Machine Learning Engineer
  • AI Engineer
  • MLOps Engineer
  • Data Engineer
  • Staff Engineer
  • Principal Engineer

TABLE OF CONTENTS

Module 1: Python Fundamentals (40 Questions)

Module 2: Data Structures (30 Questions)

Module 3: OOP Concepts (35 Questions)

Module 4: Functions & Functional Programming (20 Questions)

Module 5: Exception Handling (15 Questions)

Module 6: File Handling (15 Questions)

Module 7: Iterators & Generators (20 Questions)

Module 8: Decorators & Context Managers (20 Questions)

Module 9: Multithreading & Multiprocessing (25 Questions)

Module 10: Async Programming (20 Questions)

Module 11: Memory Management & Internals (25 Questions)

Module 12: Advanced Python (30 Questions)

Module 13: Database Programming (15 Questions)

Module 14: API Development (20 Questions)

Module 15: Pandas & NumPy (30 Questions)

Module 16: AWS + Python (40 Questions)

Module 17: Data Engineering with Python (35 Questions)

Module 18: Machine Learning & AI Python (25 Questions)

Module 19: System Design using Python (25 Questions)

Module 20: Coding Challenges (50 Questions)

Total Questions: 500+


MODULE 1: PYTHON FUNDAMENTALS

Q1. What is Python?

Python is a high-level, interpreted, object-oriented programming language developed by Guido van Rossum in 1991.

Features:

  • Easy syntax
  • Dynamically typed
  • Interpreted
  • Open source
  • Cross-platform

Example:

print("Hello World")

Q2. Why is Python popular?

Answer:

  1. Simplicity
  2. Large ecosystem
  3. AI/ML support
  4. Cloud automation
  5. Data Engineering
  6. Web development

Q3. Explain Python execution flow.

Flow:

Source Code

Byte Code (.pyc)

Python Virtual Machine

Execution

Interview Tip:
Senior interviews frequently ask this.


Q4. What is Dynamic Typing?

Python determines variable type at runtime.

x = 10
x = "Hello"

No explicit declaration required.


Q5. What are Python keywords?

Examples:

if
else
for
while
try
except
class
def
yield
async
await

Q6. Difference between Python 2 and Python 3?

FeaturePython 2Python 3
PrintStatementFunction
UnicodeLimitedFull Support
DivisionIntegerFloat
SupportEndedActive

Q7. What is PEP 8?

Python coding standard.

Example:

def calculate_salary():
pass

Best Practices:

  • 4 spaces indentation
  • Meaningful variable names
  • Maximum 79 characters per line

Q8. What are mutable objects?

Can be modified after creation.

Examples:

list
dict
set

Q9. What are immutable objects?

Cannot change after creation.

Examples:

str
tuple
int
float

Q10. Explain Python namespaces.

Types:

  1. Local
  2. Global
  3. Built-in
  4. Enclosing

LEGB Rule:

Local
Enclosing
Global
Built-in

MODULE 2: DATA STRUCTURES

Q11. Difference between List and Tuple

FeatureListTuple
MutableYesNo
SpeedSlowerFaster
MemoryMoreLess

Example:

lst = [1,2,3]
tpl = (1,2,3)

Q12. When should you use tuples?

Use tuples when:

  • Data should not change
  • Configuration storage
  • Database records
  • Dictionary keys

Q13. What is a Dictionary?

Key-value storage.

employee = {
"name":"John",
"salary":50000
}

Complexity:

Lookup O(1)
Insert O(1)
Delete O(1)

Q14. How does dictionary work internally?

Uses Hash Tables.

Steps:

  1. Key hashed
  2. Bucket identified
  3. Value stored

Q15. What is Hash Collision?

Multiple keys generate same hash value.

Resolved using:

  • Open Addressing
  • Chaining

Q16. What is Set?

Unordered collection of unique elements.

s = {1,2,3}

Use cases:

  • Duplicate removal
  • Membership testing

Q17. List Comprehension vs Loop

Traditional:

squares = []

for i in range(10):
squares.append(i*i)

Comprehension:

squares = [i*i for i in range(10)]

Q18. Time Complexity of List Operations

OperationComplexity
AccessO(1)
AppendO(1)
InsertO(n)
DeleteO(n)

Q19. Difference between append() and extend()?

append():

a.append([4,5])

extend():

a.extend([4,5])

extend adds individual elements.


Q20. Explain slicing.

nums = [1,2,3,4,5]

nums[1:4]

Output:

[2,3,4]

MODULE 3: OBJECT ORIENTED PROGRAMMING

Q21. What is OOP?

Programming based on objects.

Four Pillars:

  1. Encapsulation
  2. Inheritance
  3. Polymorphism
  4. Abstraction

Q22. What is a Class?

Blueprint for objects.

class Employee:
pass

Q23. What is an Object?

Instance of a class.

emp = Employee()

Q24. What is Constructor?

Automatically invoked during object creation.

class Employee:

def __init__(self,name):
self.name = name

Q25. What is Encapsulation?

Hides internal state.

class Account:

def __init__(self):
self.__balance = 1000

Benefits:

  • Security
  • Maintainability

Q26. What is Inheritance?

Allows code reuse.

class Animal:
pass

class Dog(Animal):
pass

Q27. Types of Inheritance?

  1. Single
  2. Multiple
  3. Multilevel
  4. Hierarchical
  5. Hybrid

Q28. What is Method Overriding?

Child class modifies parent behavior.

class Animal:
def sound(self):
pass

class Dog(Animal):
def sound(self):
print("Bark")

Q29. What is Polymorphism?

Same interface, multiple implementations.

Example:

obj.sound()

Works for Dog, Cat, Cow.


Q30. What is Abstraction?

Hide implementation details.

from abc import ABC

MODULE 4: FUNCTIONS

Q31. What are *args?

Accept variable positional arguments.

def add(*args):
return sum(args)

Q32. What are **kwargs?

Accept variable keyword arguments.

def display(**kwargs):
print(kwargs)

Q33. What is Lambda?

Anonymous function.

square = lambda x:x*x

Q34. What is map()?

Transforms elements.

map(lambda x:x*2, nums)

Q35. What is filter()?

Filters elements.

filter(lambda x:x>5, nums)

MODULE 5: EXCEPTION HANDLING

Q36. What is Exception?

Runtime error.

Examples:

  • ValueError
  • TypeError
  • IndexError
  • KeyError

Q37. Exception Handling Syntax

try:
risky()

except Exception as e:
print(e)

finally:
cleanup()

Q38. Difference between Exception and Error?

Exception:

  • Recoverable

Error:

  • Serious system issue

Q39. What is Finally?

Always executes.

Used for:

  • Closing files
  • Releasing connections

Q40. How to create custom exception?

class SalaryException(Exception):
pass

MODULE 6–20 (ADVANCED/SENIOR LEVEL)

Below are the remaining high-priority questions grouped by topic. In a real interview, these are asked more frequently than basic syntax.

GENERATORS & ITERATORS

  1. What is an iterator?
  2. What is a generator?
  3. yield vs return?
  4. Why are generators memory efficient?
  5. Generator expression vs list comprehension?
  6. Infinite generators?
  7. Itertools library?
  8. Custom iterator implementation?
  9. next() function?
  10. StopIteration exception?

DECORATORS

  1. What is a decorator?
  2. Why use decorators?
  3. Logging decorator?
  4. Authentication decorator?
  5. Timing decorator?
  6. Nested decorators?
  7. Class decorators?
  8. functools.wraps?
  9. Parameterized decorators?
  10. Production use cases?

CONTEXT MANAGERS

  1. What is context manager?
  2. enter and exit?
  3. with statement?
  4. Database connection management?
  5. Custom context manager?

THREADING & MULTIPROCESSING

  1. What is a thread?
  2. What is a process?
  3. What is GIL?
  4. Why does GIL exist?
  5. Threading vs Multiprocessing?
  6. ThreadPoolExecutor?
  7. ProcessPoolExecutor?
  8. Race conditions?
  9. Locks?
  10. Semaphores?
  11. Deadlocks?
  12. Queues?
  13. Producer Consumer pattern?
  14. Concurrent Futures?
  15. Real-world AWS use cases?

ASYNCIO

  1. What is async programming?
  2. async vs threading?
  3. async vs multiprocessing?
  4. Event loop?
  5. Coroutines?
  6. await keyword?
  7. asyncio.gather()?
  8. Task scheduling?
  9. aiohttp?
  10. High-performance APIs?

MEMORY MANAGEMENT

  1. Reference counting?
  2. Garbage collection?
  3. Circular references?
  4. Memory leaks?
  5. Weak references?
  6. Object pooling?
  7. Interning?
  8. Deep copy vs shallow copy?
  9. Memory profiler?
  10. Optimizing large ETL jobs?

PYTHON INTERNALS

  1. How import works?
  2. name?
  3. dict?
  4. slots?
  5. str vs repr?
  6. MRO?
  7. Metaclasses?
  8. Duck typing?
  9. Monkey patching?
  10. Descriptors?

DATABASES

  1. Python and MySQL?
  2. Python and PostgreSQL?
  3. Connection pooling?
  4. SQL injection prevention?
  5. ORM vs raw SQL?
  6. SQLAlchemy?
  7. Transactions?
  8. ACID properties?
  9. Bulk inserts?
  10. Database optimization?

FASTAPI / FLASK

  1. What is FastAPI?
  2. Why FastAPI is popular?
  3. Dependency Injection?
  4. Pydantic?
  5. REST API design?
  6. JWT authentication?
  7. API versioning?
  8. Middleware?
  9. Rate limiting?
  10. OpenAPI?

NUMPY

131–150.

  • Arrays
  • Broadcasting
  • Vectorization
  • Memory optimization
  • Matrix operations
  • Linear algebra
  • Random module
  • NumPy internals
  • Performance tuning

PANDAS

151–180.

  • DataFrame
  • Series
  • Merge
  • Join
  • Concat
  • GroupBy
  • Window Functions
  • Missing values
  • Pivot tables
  • Performance tuning

AWS + PYTHON (MOST IMPORTANT FOR USA JOBS)

  1. What is Boto3?
  2. Upload file to S3?
  3. Download from S3?
  4. Read DynamoDB?
  5. Write DynamoDB?
  6. Invoke Lambda?
  7. Start Glue Job?
  8. Read Secrets Manager?
  9. KMS Encryption?
  10. Assume IAM Role?
  11. Cross-account access?
  12. SQS integration?
  13. SNS integration?
  14. Step Functions?
  15. EventBridge?
  16. Athena automation?
  17. Redshift integration?
  18. Bedrock API integration?
  19. SageMaker automation?
  20. CloudFormation automation?

DATA ENGINEERING

  1. Build ETL in Python?
  2. Process 1 TB file?
  3. Chunk processing?
  4. Streaming ETL?
  5. PySpark integration?
  6. Dask?
  7. Airflow DAGs?
  8. Data validation?
  9. Schema evolution?
  10. Data quality checks?
  11. CDC processing?
  12. Kafka consumers?
  13. Kafka producers?
  14. Batch vs Streaming?
  15. Delta Lake?

MACHINE LEARNING

  1. NumPy importance?
  2. Pandas role?
  3. Feature engineering?
  4. Scikit-learn?
  5. Model serialization?
  6. Pickle issues?
  7. ML pipelines?
  8. Hyperparameter tuning?
  9. Feature stores?
  10. Model serving?

GENERATIVE AI

  1. What is RAG?
  2. Vector database?
  3. Chunking strategies?
  4. Embeddings?
  5. Amazon Bedrock?
  6. LangChain?
  7. LlamaIndex?
  8. Prompt engineering?
  9. Hallucination?
  10. Agentic AI?

SYSTEM DESIGN (SENIOR)

  1. Design URL Shortener
  2. Design Netflix
  3. Design Uber
  4. Design ChatGPT
  5. Design Data Lake
  6. Design ETL Framework
  7. Design Log Processing Platform
  8. Design Notification System
  9. Design Real-Time Analytics
  10. Design AI Platform

PRINCIPAL ENGINEER LEVEL

  1. How would you redesign a Python monolith?
  2. Scaling Python to millions of requests?
  3. Python microservices architecture?
  4. Multi-region deployment?
  5. Event-driven architecture?
  6. High availability?
  7. Fault tolerance?
  8. Distributed locking?
  9. Caching strategy?
  10. API Gateway design?
  11. Service Mesh?
  12. Observability?
  13. OpenTelemetry?
  14. Cost optimization?
  15. Reliability engineering?

AMAZON / FAANG PYTHON QUESTIONS

  1. Mutable default argument issue?
  2. is vs ==?
  3. Deep copy issue?
  4. Decorator internals?
  5. Generator internals?
  6. Context manager internals?
  7. Async internals?
  8. Metaclass use cases?
  9. MRO diamond problem?
  10. Python optimization techniques?

CODING QUESTIONS (COMMON)

  1. Reverse string
  2. Palindrome
  3. Fibonacci
  4. Factorial
  5. Anagram
  6. Find duplicates
  7. LRU Cache
  8. Linked List
  9. Binary Search
  10. DFS
  11. BFS
  12. Tree Traversal
  13. Graph Traversal
  14. Dijkstra
  15. Merge Intervals
  16. Top K Elements
  17. Sliding Window
  18. Two Sum
  19. Longest Substring
  20. Kth Largest Element

SENIOR CODING

  1. Rate Limiter
  2. Distributed Cache
  3. Thread-safe Queue
  4. Async Web Crawler
  5. ETL Framework
  6. Retry Framework
  7. Circuit Breaker
  8. Pub/Sub System
  9. Job Scheduler
  10. Mini API Gateway

U.S. Interview Focus Areas (Highest Priority)

If you are targeting:

  • AWS Data Engineer
  • AI Engineer
  • Cloud Engineer
  • Solutions Architect
  • Senior Python Engineer

Focus heavily on:

  1. OOP
  2. Generators
  3. Decorators
  4. Context Managers
  5. Threading vs Multiprocessing
  6. Asyncio
  7. Memory Management
  8. Pandas
  9. NumPy
  10. Boto3
  11. FastAPI
  12. ETL Design
  13. PySpark
  14. Airflow
  15. RAG
  16. Amazon Bedrock
  17. System Design
  18. Distributed Systems
  19. API Design
  20. Python Internals

These 20 areas account for the majority of Python questions asked in mid-level to principal-level interviews across companies such as Amazon, Microsoft, Google, Meta, and large U.S. enterprises.

🤞 Sign up for our newsletter!

We don’t spam! Read more in our privacy policy

Scroll to Top