Interview Preparation
Python Interview Questions and Answers for Experienced Professionals โ 2026
These are the most commonly asked Python interview questions for experienced professionals in 2026 โ compiled by Vtricks faculty based on real interview feedback from students placed at companies like Amazon, Google, Infosys, Capgemini, TCS, Zoho in Bangalore.
There are currently 6,800+ active Python job openings in Bangalore. Freshers can expect โน4โ7 LPA at companies across Bangalore's tech corridor โ Whitefield, Electronic City, Koramangala, and the CBD. Preparation matters: candidates who practise these questions consistently perform significantly better in technical rounds.
Interview Tips from Vtricks Faculty
- Always explain your reasoning process โ interviewers want to see how you think, not just the final answer.
- Use real examples from projects you have worked on when answering scenario-based questions.
- If you don't know the answer, say so honestly and describe how you would find the answer โ this is better than guessing.
- For Bangalore companies specifically: be ready to answer follow-up questions โ they often go 2-3 levels deep on any concept.
- Always ask clarifying questions before answering complex scenario-based questions โ this demonstrates professional problem-solving approach.
Easy โ basic concept check
Medium โ applied knowledge
Hard โ senior/deep dive
All 16 Questions
Python Interview Questions โ Experienced Professionals
Q1. What is Python's GIL and how does it affect multi-threading?
Technical
Hard
ANSWER
The Global Interpreter Lock (GIL) is a mutex in CPython that allows only one thread to execute Python bytecode at a time, even on multi-core systems. This prevents race conditions but limits CPU parallelism for multi-threaded Python programs. Impact: I/O-bound tasks (network calls, file operations) still benefit from threading because threads release the GIL during I/O waits. CPU-bound tasks (calculations, image processing) do NOT benefit from threading due to the GIL โ use multiprocessing module instead, which creates separate processes each with their own GIL. Alternatively, use PyPy, Cython, or concurrent.futures.
Q2. Explain Python's metaclasses.
Technical
Hard
ANSWER
A metaclass is a class whose instances are classes โ it defines how classes behave. In Python, the default metaclass is 'type'. You can define custom metaclasses to control class creation, validation, and modification. Use cases: enforcing coding standards across all classes in a framework, creating singletons, automatic registration of subclasses (like Django's ORM model registration), adding logging or validation to all methods. Define using class Meta(type): and pass it to your class: class MyClass(metaclass=Meta). Metaclasses are a powerful but complex feature โ use only when design patterns like decorators or mixins are insufficient.
Q3. How do you optimise Python code for performance?
Technical
Hard
ANSWER
Key techniques: Use built-in functions and libraries (map, filter, sorted) which are implemented in C. Use list comprehensions over for loops for simple transformations. Use generators instead of lists for large datasets. Profile with cProfile before optimising โ optimise only bottlenecks. Use NumPy for numerical computations โ vectorised operations are 10-100ร faster than Python loops. Use local variables inside functions โ Python looks up locals faster than globals. Use __slots__ in classes to reduce memory. Use multiprocessing for CPU-bound tasks. Use async/await with asyncio for I/O-bound concurrent tasks. Compile with Cython or use PyPy for further speedups.
Q4. What is asyncio and when do you use async/await in Python?
Technical
Hard
ANSWER
asyncio is Python's built-in library for writing concurrent code using the async/await syntax โ an event loop runs coroutines that yield control when waiting for I/O. Use async/await for I/O-bound tasks: making hundreds of simultaneous HTTP requests, database queries, file operations โ without blocking. Do NOT use it for CPU-bound tasks (use multiprocessing). Key concepts: async def defines a coroutine. await suspends the coroutine until the awaited task completes. asyncio.gather() runs multiple coroutines concurrently. Example: fetching data from 1000 APIs simultaneously using aiohttp with asyncio is 50-100ร faster than sequential requests.
Master These Questions
Practice Python with Live Mentors at Vtricks
400+ students placed ยท 85% placement rate ยท Starts at โน25,000
Free Demo Class โ
Q5. What is the difference between pickling and JSON serialisation?
Technical
Medium
ANSWER
Pickle serialises Python objects to a binary format โ it can handle arbitrary Python objects including custom classes, functions, and complex data structures. It is Python-specific and not human-readable. Security risk: never unpickle data from untrusted sources. JSON serialisation converts Python objects to a human-readable text format that is language-agnostic. JSON supports only basic types: strings, numbers, lists, dicts, booleans, null. Use JSON for APIs and data exchange between systems. Use pickle for saving Python objects to disk for later use within the same Python application.
Q6. Explain Python's descriptor protocol.
Technical
Hard
ANSWER
A descriptor is any object that defines __get__, __set__, or __delete__ methods โ these control attribute access. Python uses descriptors internally for properties, classmethod, staticmethod, and functions. Data descriptors define both __get__ and __set__. Non-data descriptors define only __get__. Lookup priority: data descriptors > instance variables > non-data descriptors. Use cases: creating reusable attribute validation logic (type checking, range validation) that works across multiple classes, implementing lazy attributes that compute values on first access, ORM fields (Django's model Field classes are descriptors).
Q7. How does Django's ORM work and what are its limitations?
Technical
Hard
ANSWER
Django ORM maps Python classes (models) to database tables and generates SQL automatically. It provides a QuerySet API for database operations without writing SQL. How it works: Model class โ Database table, Model fields โ Table columns, QuerySet โ SQL query (lazy evaluation until needed). Limitations: Complex queries can generate inefficient SQL โ use select_related() and prefetch_related() to avoid N+1 query problems. For very complex analytics queries, write raw SQL using Model.objects.raw() or Django's connection.execute(). The ORM adds overhead compared to direct SQL. Not ideal for bulk operations โ use bulk_create() and bulk_update(). Use Django Debug Toolbar to monitor generated queries.
Q8. What are Python's context managers and how do you create custom ones?
Technical
Medium
ANSWER
Context managers manage resources by ensuring setup and cleanup code runs correctly using the with statement. Python calls __enter__ when entering the with block and __exit__ when leaving (even if an exception occurs). Built-in examples: open() for files, threading.Lock() for thread safety. Create custom context managers two ways: Class-based โ implement __enter__ and __exit__ methods. Generator-based โ use @contextlib.contextmanager decorator with yield. Use cases: database transactions, temporary directory creation, timing code blocks, managing network connections.
Q9. Explain Python's import system and circular imports.
Technical
Hard
ANSWER
When you import a module, Python checks sys.modules cache first โ if found, returns cached module. If not, finds the module using sys.path, compiles to bytecode (.pyc), executes the module code, and caches it. Circular imports occur when module A imports module B and module B imports module A. Python partially initialises A before completing B, which may cause AttributeError when B tries to access something not yet defined in A. Solutions: move the import inside the function that uses it (local import), restructure code to remove the circular dependency, use importlib for dynamic imports, or create a shared module that both A and B import from.
Master These Questions
Practice Python with Live Mentors at Vtricks
400+ students placed ยท 85% placement rate ยท Starts at โน25,000
Free Demo Class โ
Q10. How do you implement caching in Python?
Technical
Medium
ANSWER
Caching stores results of expensive computations for reuse. Options: functools.lru_cache() decorator โ caches function results in memory with a configurable max size, automatically evicts least recently used entries. functools.cache() in Python 3.9+ โ unbounded LRU cache. Redis caching for distributed applications โ store results across multiple servers. Django's cache framework supports multiple backends (memcached, Redis, database, file). Flask-Caching extension. Manual dict-based caching for simple cases. Cache invalidation strategy is critical โ decide when cached values expire or are invalidated based on data freshness requirements.
Q11. What are Python dataclasses and when do you use them?
Technical
Medium
ANSWER
Dataclasses (Python 3.7+) are classes decorated with @dataclass that automatically generate __init__, __repr__, __eq__ and other dunder methods based on class variable annotations. They reduce boilerplate for data container classes. Use dataclasses when: you need a simple class to store data with typed fields, you want auto-generated equality and representation, you need optional immutability (@dataclass(frozen=True)). Advantages over namedtuple: mutable by default, support inheritance, support default factories. Advantages over regular classes: less code. Use Pydantic for more advanced validation and serialisation.
Q12. Explain the SOLID principles in Python with examples.
Conceptual
Hard
ANSWER
SOLID: Single Responsibility โ each class does one thing only (separate UserAuth from UserProfile). Open/Closed โ open for extension, closed for modification โ use inheritance or composition instead of modifying existing classes. Liskov Substitution โ subclasses must be usable wherever their parent class is used without breaking the program. Interface Segregation โ don't force classes to implement interfaces they don't use โ use multiple small interfaces instead of one large one. Dependency Inversion โ high-level modules should not depend on low-level modules; both should depend on abstractions. Apply these to write maintainable, testable Python code especially in Django or Flask applications.
Q13. What is test-driven development in Python?
Technical
Medium
ANSWER
TDD is a development process where you write tests before writing the implementation code. Cycle: Red โ write a failing test that defines desired behaviour. Green โ write minimum code to make the test pass. Refactor โ improve code quality while keeping tests green. Python testing tools: unittest (built-in), pytest (most popular โ simpler syntax, powerful fixtures), mock (unittest.mock for replacing dependencies). Pytest features: fixtures for setup/teardown, parametrize for testing multiple inputs, markers for categorising tests. Good tests follow FIRST: Fast, Independent, Repeatable, Self-validating, Timely.
Q14. How do you handle database migrations in a Python web application?
Technical
Medium
ANSWER
Database migrations track and apply schema changes over time. In Django: python manage.py makemigrations creates migration files when you change models; python manage.py migrate applies them to the database. Key practices: always commit migration files to version control; never edit applied migrations โ create new ones; use squashmigrations to combine old migrations; test migrations in staging before production; for large tables, use data migrations separately from schema migrations to avoid locking tables. In Flask with SQLAlchemy, use Flask-Migrate (built on Alembic) which provides the same workflow.
Master These Questions
Practice Python with Live Mentors at Vtricks
400+ students placed ยท 85% placement rate ยท Starts at โน25,000
Free Demo Class โ
Q15. What is a REST API and how do you build one in Python?
Technical
Medium
ANSWER
A REST API is an architectural style for building web services using HTTP methods: GET (retrieve), POST (create), PUT/PATCH (update), DELETE (remove). Resources are accessed via URLs. In Python: Django REST Framework (DRF) is the most popular for Django apps โ provides serialisers, viewsets, authentication, and browsable API. Flask with Flask-RESTful or Flask-RESTx for lightweight APIs. FastAPI is the modern choice โ uses Python type hints, auto-generates OpenAPI documentation, and is the fastest Python web framework. Key considerations: versioning (/api/v1/), authentication (JWT, OAuth), pagination, rate limiting, consistent error responses.
Q16. Explain memory leaks in Python and how to debug them.
Technical
Hard
ANSWER
Memory leaks in Python occur when objects are kept in memory longer than needed โ usually due to: Circular references not caught by the cyclic garbage collector. Global variables holding large objects. Closures capturing outer scope variables. Cache growing without bound. Event listeners not unregistered. To debug: use tracemalloc (Python 3.4+) to take memory snapshots and compare. Use objgraph to visualise object references and find unexpected reference chains. Use memory_profiler to profile line-by-line memory usage. Use gc module to manually trigger collection and inspect uncollectable objects. Check for __del__ methods in circular references โ these prevent garbage collection.
Company Insights
What Python Companies in Bangalore Actually Ask
Based on interview feedback from Vtricks students placed at Bangalore companies in 2026:
Round 1 โ Written/Online Test
Most Bangalore companies start with a written or online test covering python fundamentals, multiple choice questions on Python and Django, and basic problem-solving questions. Duration: 30โ60 minutes. Companies like Amazon and Google use platforms like HackerRank or their own internal assessments.
Round 2 โ Technical Interview (Most Important)
This is where most candidates are filtered. Expect: direct questions from this list, hands-on tasks (write a SQL query, debug a piece of code, explain a dashboard you built), and scenario-based questions where you walk through how you would solve a real problem. Be prepared to share your screen and code live.
Round 3 โ Managerial / HR Round
Focuses on: why you chose python as a career, how you handle ambiguous requirements, a project you are proud of (have this ready in detail โ situation, what you did, result), and salary expectations. Research the company's tech stack and recent news before this round.
Tools You Must Be Able to Demonstrate
- Python โ be ready to use this live in an interview
- Django โ be ready to use this live in an interview
- Flask โ be ready to use this live in an interview
- Pandas โ be ready to use this live in an interview
- NumPy โ be ready to use this live in an interview
- Scikit-learn โ be ready to use this live in an interview
More Resources
More Python Interview Preparation
Prepare for Your Python Interview at Vtricks
Our students practise all these questions with live mentors and get placed at top Bangalore companies. Join 400+ students already working in Python.
Mock interviews with mentors
Live daily classes
85% placement rate
Starts at โน25,000
Book Free Demo Class at Vtricks โ
Vijayanagar, Bangalore ยท Online also available ยท No payment required