These are the most asked Python interview questions in 2026 — covering freshers to experienced level. These questions are commonly asked at TCS, Infosys, Wipro, HCL, Google, Amazon, Flipkart, and startups. Each answer is concise and interview-ready.
🟢 Basic (14) 🟡 Intermediate (10) 🔴 Advanced (6)
Q1 What is Python? Why is it popular? Basic
Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum in 1991. It's popular because: readable syntax (like English), huge library ecosystem (400K+ packages), versatile (web, AI, data, automation), strong community, and it's the #1 language on TIOBE Index 2026.
Q2 What are Python's key features? Basic
Interpreted (no compilation), dynamically typed (no type declarations), object-oriented, extensive standard library, cross-platform, garbage collected (automatic memory management), supports multiple paradigms (OOP, functional, procedural).
Q3 What is the difference between a List and a Tuple? Basic
List: mutable (can change), uses [], slightly slower. Tuple: immutable (cannot change), uses (), faster, can be used as dictionary keys. Use tuples for fixed data (coordinates, RGB), lists for collections that change.
Q4 Explain Python's memory management. Intermediate
Python uses: reference counting (tracks how many variables point to an object), garbage collector (cleans cyclic references), private heap (all objects stored here), memory pool (small object allocation). The gc module handles automatic cleanup.
Q5 What are *args and **kwargs? Intermediate
*args allows a function to accept any number of positional arguments (as a tuple). **kwargs allows any number of keyword arguments (as a dictionary). Example: def func(*args, **kwargs) can be called as func(1, 2, name="Rahul").
Q6 What is a decorator in Python? Intermediate
A decorator is a function that wraps another function to add behavior without modifying it. Uses @syntax. Example: @login_required in Django checks authentication before running the view function. Common in Flask (@app.route), logging, caching.
Q7 Explain list comprehension with an example. Basic
List comprehension creates lists in one line: [expression for item in iterable if condition]. Example: squares = [x**2 for x in range(10) if x % 2 == 0] gives [0, 4, 16, 36, 64]. It's faster and more Pythonic than equivalent for loops.
Q8 What is the difference between == and is? Intermediate
== checks value equality (do they have the same content?). is checks identity (are they the same object in memory?). Example: a = [1,2]; b = [1,2]; a == b is True, but a is b is False (different objects with same value).
Q9 What are generators? How are they different from lists? Intermediate
Generators produce values lazily using yield — one at a time, on demand. Lists store all values in memory at once. Generators are memory-efficient for large datasets. Example: (x**2 for x in range(1000000)) uses almost no memory vs [x**2 for x in range(1000000)].
Q10 Explain Python's GIL (Global Interpreter Lock). Advanced
GIL is a mutex that allows only one thread to execute Python bytecode at a time. This means Python threads can't achieve true parallelism for CPU-bound tasks. Workarounds: multiprocessing module, asyncio for I/O-bound tasks, or using C extensions.
Q11 What is the difference between shallow copy and deep copy? Intermediate
Shallow copy (copy.copy()) creates a new object but references the same nested objects. Deep copy (copy.deepcopy()) creates completely independent copies of all nested objects. Matters when you have lists inside lists or objects inside objects.
Q12 How does Python handle exceptions? Basic
Using try/except/else/finally blocks. try: risky code. except SpecificError: handle it. else: runs if no error. finally: always runs (cleanup). Best practice: catch specific exceptions, never bare except:. Use raise to throw custom exceptions.
Q13 What is __init__ and self in Python classes? Basic
__init__ is the constructor method — called automatically when creating an object. self refers to the current instance of the class. self.name = name stores the parameter as an instance attribute. Every method's first parameter must be self.
Q14 Explain inheritance in Python. Intermediate
Inheritance lets a child class reuse code from a parent class. class Child(Parent): inherits all methods/attributes. Use super().__init__() to call parent constructor. Python supports multiple inheritance: class C(A, B). MRO (Method Resolution Order) determines which method is called.
Q15 What is the difference between append() and extend()? Basic
append(x) adds x as a single element (even if x is a list). extend(iterable) adds each element of the iterable individually. Example: [1,2].append([3,4]) → [1,2,[3,4]]. [1,2].extend([3,4]) → [1,2,3,4].
Q16 Write a Python program to reverse a string. Basic
Multiple ways: 1) Slicing: s[::-1] (most Pythonic). 2) reversed(): "".join(reversed(s)). 3) Loop: build new string character by character. The slicing method is fastest and most commonly expected in interviews.
Q17 What are Python's built-in data types? Basic
Numeric: int, float, complex. Sequence: str, list, tuple, range. Set: set, frozenset. Mapping: dict. Boolean: bool. Binary: bytes, bytearray, memoryview. None: NoneType. Most used in interviews: list, dict, tuple, set, str.
Q18 What is a lambda function? Basic
A small anonymous function defined with lambda keyword. Syntax: lambda args: expression. Example: square = lambda x: x**2. Used with map(), filter(), sorted(). Limited to single expression — for complex logic, use regular def functions.
Q19 Explain map(), filter(), and reduce(). Intermediate
map(func, iterable): applies func to every item, returns iterator. filter(func, iterable): keeps items where func returns True. reduce(func, iterable): combines all items into one value (from functools). Example: list(map(lambda x: x*2, [1,2,3])) → [2,4,6].
Q20 What is PEP 8? Basic
PEP 8 is Python's official style guide. Key rules: 4 spaces for indentation, max 79 chars per line, snake_case for functions/variables, CamelCase for classes, 2 blank lines between top-level definitions. Following PEP 8 makes code readable and professional.
Q21 How is Python different from Java? Basic
Python: interpreted, dynamically typed, concise syntax, indentation-based blocks. Java: compiled to bytecode, statically typed, verbose syntax, curly-brace blocks. Python is faster to write; Java is faster to execute. Python for AI/scripting; Java for enterprise/Android.
Q22 What is a virtual environment? Intermediate
A virtual environment is an isolated Python installation for a specific project. It prevents package conflicts between projects. Create: python -m venv myenv. Activate: source myenv/bin/activate (Linux) or myenv\Scripts\activate (Windows). Use requirements.txt to share dependencies.
Q23 Explain file handling in Python. Basic
Use open(filename, mode) with with statement. Modes: r (read), w (write/overwrite), a (append), rb (read binary). with open("file.txt", "r") as f: content = f.read(). The with statement auto-closes the file. Always prefer with over manual open/close.
Q24 What is the difference between a module and a package? Intermediate
Module: a single .py file containing functions/classes. Package: a directory containing multiple modules + an __init__.py file. Example: math is a module, numpy is a package (contains many modules like numpy.random, numpy.linalg).
Q25 Write a program to check if a number is prime. Basic
def is_prime(n): if n < 2: return False; for i in range(2, int(n**0.5)+1): if n%i==0: return False; return True. Key optimization: only check up to √n (not n). Time complexity: O(√n). This is the standard interview answer.
Q26 What are dunder/magic methods? Advanced
Methods with double underscores: __init__, __str__, __repr__, __len__, __add__, __eq__, etc. They let you define how objects behave with operators and built-in functions. __str__ defines print() output, __len__ defines len() behavior, __add__ defines + operator.
Q27 Explain Python's dictionary implementation. Advanced
Python dicts use hash tables internally. Keys are hashed to determine storage location. This gives O(1) average lookup/insert/delete time. Keys must be hashable (immutable): strings, numbers, tuples. Since Python 3.7, dicts maintain insertion order.
Q28 What is asyncio in Python? Advanced
asyncio is Python's library for asynchronous programming. It uses async/await syntax to handle I/O-bound tasks concurrently without threads. Perfect for: web scraping, API calls, database queries, file I/O. Not useful for CPU-bound tasks (use multiprocessing instead).
Q29 How would you optimize a slow Python program? Advanced
1) Profile first (cProfile). 2) Use built-in functions (they're C-optimized). 3) List comprehensions over loops. 4) Use generators for large data. 5) Cache with @lru_cache. 6) Use NumPy for numerical operations. 7) Consider PyPy or Cython for critical sections.
Q30 What is the difference between process and thread in Python? Advanced
Thread: lightweight, shares memory, limited by GIL (no true parallelism for CPU tasks). Process: heavyweight, separate memory, true parallelism. Use threading for I/O-bound tasks (network, file). Use multiprocessing for CPU-bound tasks (calculations, data processing).
Interview Preparation Tips
- Practice coding on paper — many companies still use whiteboard interviews
- Explain your thought process while solving — interviewers value communication
- Know time/space complexity of your solutions (Big O notation)
- Build 2-3 projects and be ready to explain every line of code
- For TCS/Infosys: focus on Basic + Intermediate questions
- For Google/Amazon: all levels + DSA + system design basics
Continue Learning
People Also Search For
python interview questions freshers 2026 TCS python interview questions python coding interview questions python OOP interview questions python viva questions for BCA infosys python questions python interview for experienced python data structure interview python decorator interview question python placement questions 2026