Python Interview Questions & Answers (2025 Edition)
1. What is Python?
Python is a high-level, interpreted, dynamically typed language known for readability and rapid development.
2. Difference between list
, tuple
, and set
-
list
: mutable, ordered -
tuple
: immutable, ordered -
set
: mutable, unordered, unique elements
3. Difference between ==
and is
-
==
: checks value equality -
is
: checks object identity
4. Mutable vs Immutable types
-
Mutable:
list
,dict
,set
(can change in place) -
Immutable:
int
,float
,str
,tuple
(cannot change)
5. What is a Python function?
Defined using def
, functions encapsulate reusable logic.
6. What are Python’s data types?
-
Numeric:
int
,float
,complex
-
Sequence:
list
,tuple
,range
-
Text:
str
-
Set:
set
,frozenset
-
Mapping:
dict
-
Boolean:
bool
7. What is None
in Python?
Represents the absence of a value.
8. Explain Python’s indentation
Python uses indentation to define code blocks instead of braces.
9. What is the difference between append()
and extend()
?
10. How to swap variables in Python?
Medium Questions (11–20)
11. Explain closures in Python
A closure remembers variables from its enclosing scope.
12. What are decorators?
Functions that modify the behavior of other functions.
13. Difference between *args
and **kwargs
-
*args
: variable number of positional arguments -
**kwargs
: variable number of keyword arguments
14. Python’s LEGB rule
Variable lookup order: Local → Enclosing → Global → Built-in
15. What are Python modules and packages?
-
Module: a
.py
file containing code -
Package: folder containing multiple modules and
__init__.py
16. Explain map()
, filter()
, reduce()
-
map()
: transforms elements -
filter()
: selects elements -
reduce()
: aggregates elements
17. Python list comprehension
Concise way to create lists.
18. Explain with
statement
Automatically handles resource management, e.g., file closing.
19. Difference between shallow and deep copy
-
Shallow copy: copies references
-
Deep copy: copies objects fully
20. Python’s pass
, break
, continue
-
pass
: does nothing -
break
: exits loop -
continue
: skips iteration
Difficult Questions (21–30)
21. Python’s GIL (Global Interpreter Lock)
Prevents multiple native threads from executing Python bytecodes simultaneously; affects CPU-bound threading.
22. Difference between @staticmethod
and @classmethod
23. Generators in Python
Yield values lazily to save memory.
24. Python’s __init__
vs __new__
-
__init__
: initializes object after creation -
__new__
: creates a new instance
25. Python memory management
Uses reference counting and garbage collection. Manual collection with gc
is also possible.
26. Explain Python’s MRO (Method Resolution Order)
Determines order of class method lookup in multiple inheritance.
27. Python’s @property
decorator
Allows method access as attribute.
28. Python’s exception handling
Use try
, except
, finally
.
29. What is monkey patching?
Dynamically modifying classes or modules at runtime.
30. Python’s asyncio
Supports asynchronous programming using async
and await
.
✍️ By Not available | 2025-10-21T08:58:25.823Z