Python intermediate interview questions [Updated]
Deep Dive: Python Intermediate Interview Questions for Career Growth
Python intermediate interview questions are designed to test a candidateβs ability to apply Python concepts beyond the beginner level. If you’re preparing for technical interviews, it’s essential to practice not only basic syntax but also focus on python intermediate questions and python intermediate coding questions that evaluate your understanding of real-world problem solving and advanced language features.
Table Of Content
- Deep Dive: Python Intermediate Interview Questions for Career Growth
- Python Intermediate Coding Questions
- 1. What are Python decorators?
- 2. Explain list comprehension and its advantages.
- 3. What is the difference between is and == in Python?
- 4. What are Python generators?
- 5. Explain Pythonβs garbage collection.
- 6. What is a lambda function in Python?
- 7. What are *args and kwargs?
- 8. What is the difference between a shallow copy and a deep copy?
- 9. How is exception handling done in Python?
- 10. What is a Python module and package?
- 11. What is the difference between classmethod, staticmethod, and instance methods?
- 12. What is the purpose of __init__.py?
- 13. What is monkey patching in Python?
- 14. What are Pythonβs magic methods?
- 15. How do you handle files in Python?
- 16. How do you manage memory in Python?
- 17. What is the difference between @property and a method?
- 18. What is a Python context manager?
- 19. Explain Pythonβs GIL (Global Interpreter Lock).
- 20. How to use map, filter, and reduce?
- 21. Difference between sort() and sorted()?
- 22. What is the purpose of enumerate()?
- 23. What are Pythonβs data classes?
- 24. What are Python sets and their features?
- Key Features of Python Sets
- 25. Explain Pythonβs zip() function.
- 26. How to handle JSON in Python?
- 27. What are Python assertions?
- 28. What is the difference between del, remove(), and pop()?
- 29. Explain slicing with examples.
- 30. What is the difference between __str__() and __repr__()?
- 31. What is a metaclass in Python?
- 32. Explain type hinting.
- 33. What is duck typing?
- 34. Explain the use of super().
- 35. What are frozensets?
- 36. What is the use of globals() and locals()?
- 37. How do you use list and dictionary comprehensions?
- 38. Explain try...except...else...finally.
- 39. Are arguments passed by value or reference in Python?
- 40. Difference between iterator and iterable?
- 41. Explain multithreading vs multiprocessing in Python.
- 42. Explain Pythonβs logging module.
- 43. What is the yield from expression?
- Key Points about yield from
- β Mastering Python Intermediate Coding Questions: What to Expect and How to Prepare
- πΉ Use of Data Structures
- πΉ Working with Functional Programming
- πΉ File Handling and Exception Management
- πΉ Object-Oriented Design
- πΉ Decorators and Generators
- Common Python intermediate interview questions
- Benefits of Practicing Python Intermediate Interview Questions
- β Final Thoughts on Python Intermediate Questions
Python is a general-purpose, dynamic, high-level, and interpreted programming language. It supports the object-oriented programming approach, which makes it a popular choice for developing robust applications. Its simple and readable syntax makes it easy to learn, yet its capabilities are powerful enough for enterprise-grade solutions.
Being an interpreted language, Python allows for rapid application development and scripting. Its dynamic typing and clean syntax make it ideal for beginners and professionals alike. However, in python intermediate interview questions, youβll often encounter topics that go deeperβlike decorators, list comprehensions, exception handling, and generators.
This versatility is reflected in the variety of python intermediate questions asked during interviews. You may be asked to build classes, implement interfaces, or manipulate data using functional techniques like map(), filter(), and lambda expressions.
One of the reasons Python stands out is its dynamic nature. You donβt need to specify data types explicitly. For example, simply writing a = 10 assigns an integer value to the variable without any type declaration. This flexibility speeds up development but also introduces challenges that are commonly addressed in python intermediate coding questions.
Python Intermediate Coding Questions

1. What are Python decorators?
Answer:
Decorators are a powerful tool in Python used to modify the behavior of a function or class. They are applied using the @decorator_name syntax above the function definition. Internally, a decorator is a higher-order function that takes a function as input and returns a new function with enhanced behavior.
2. Explain list comprehension and its advantages.
Answer:
List comprehension provides a concise way to create lists in Python. It’s faster and more readable than traditional for-loops.
Advantages:
-
More compact code
-
Better performance
-
Easier to understand when used properly
3. What is the difference between is and == in Python?
Answer:
-
==checks value equality (whether the values are the same). -
ischecks identity (whether the two references point to the same object in memory).
4. What are Python generators?
Answer:
Generators are iterators created using functions and the yield keyword. They are memory-efficient and produce values one at a time.
5. Explain Pythonβs garbage collection.
Answer:
Python has an automated garbage collector that uses reference counting and cyclic garbage collection to free up unused memory.
-
Reference Count: If an objectβs reference count drops to 0, it is garbage collected.
-
Cyclic GC: Detects and collects cycles of unreachable objects.
6. What is a lambda function in Python?
Answer:
Lambda functions are anonymous, single-expression functions defined using the lambda keyword.
7. What are *args and kwargs?
Answer:
-
*args: Accepts variable number of positional arguments. -
**kwargs: Accepts variable number of keyword arguments.
8. What is the difference between a shallow copy and a deep copy?
Answer:
-
Shallow copy creates a new object but inserts references to the same objects.
-
Deep copy creates a new object and recursively copies all objects.
11. What is the difference between classmethod, staticmethod, and instance methods?
Answer:
-
@classmethodtakesclsas the first argument and can access class variables. -
@staticmethoddoesn’t takeselforclsand behaves like a normal function. -
Instance methods take
selfand can access instance variables.
12. What is the purpose of __init__.py?
Answer:
It marks a directory as a Python package and allows imports from it. It can also run initialization code.
13. What is monkey patching in Python?
Answer:
Monkey patching is dynamically changing a class or module at runtime.
14. What are Pythonβs magic methods?
Answer:
Magic methods (dunder methods) begin and end with double underscores, like __init__, __str__, __len__, etc., and define behavior of objects.
15. How do you handle files in Python?
Answer:
Using open(), read(), write(), and context managers:
16. How do you manage memory in Python?
Answer:
Python handles memory with:
-
Reference counting
-
Automatic garbage collection
-
Memory pools (via PyMalloc)
17. What is the difference between @property and a method?
Answer:@property allows a method to be accessed like an attribute.
18. What is a Python context manager?
Answer:
Used to manage resources (files, sockets) with with statement. Automatically handles __enter__ and __exit__.
19. Explain Pythonβs GIL (Global Interpreter Lock).
Answer:
GIL allows only one thread to execute Python bytecode at a time. It limits multithreading but is needed for memory safety.
20. How to use map, filter, and reduce?
Answer:
-
map()applies a function to all items. -
filter()selects items based on a condition. -
reduce()(from functools) applies cumulative function.
21. Difference between sort() and sorted()?
Answer:
-
sort()modifies the list in-place. -
sorted()returns a new sorted list.
22. What is the purpose of enumerate()?
Answer:
Returns both index and item while iterating:
23. What are Pythonβs data classes?
Python’s data classes, introduced in Python 3.7 via PEP 557, are a decorator-based feature (@dataclass) designed to simplify the creation of classes that primarily store data. They automatically generate common methods like init, repr, eq, and others, reducing boilerplate code for classes that act as structured data containers.
24. What are Python sets and their features?
Python sets are unordered collections of unique, immutable elements. They are useful for operations involving membership testing, removing duplicates, and performing mathematical set operations.
Key Features of Python Sets:
- Unordered: Elements have no specific order, so indexing or slicing is not possible.
- Unique Elements: Duplicate elements are automatically removed.
- Mutable: Sets can be modified (add/remove elements), but the elements themselves must be immutable (e.g., numbers, strings, tuples).
- Dynamic: Sets can grow or shrink as elements are added or removed.
- No Indexing: Since sets are unordered, elements cannot be accessed via indices.
- Hashable Elements: Elements in a set must be hashable (i.e., they must have a valid __hash__ method).
25. Explain Pythonβs zip() function.
26. How to handle JSON in Python?
Answer:
Python provides the json module to parse and manipulate JSON data.
28. What is the difference between del, remove(), and pop()?
Answer:
-
delremoves by index or variable reference. -
remove()deletes the first occurrence of a value. -
pop()removes and returns the element at a given index.
29. Explain slicing with examples.
Answer:
Slicing extracts a portion of a list, tuple, or string: list[start:stop:step].
30. What is the difference between __str__() and __repr__()?
Answer:
-
__str__()is for user-friendly string representation. -
__repr__()is for developers/debugging and should be unambiguous.
31. What is a metaclass in Python?
Answer:
A metaclass is a class of a class. It defines how classes behave and are constructed. You can customize class creation using metaclasses.
32. Explain type hinting.
Answer:
Type hinting allows you to specify the expected data types of function arguments and return values.
It helps with code readability and tooling (e.g., static analysis with mypy).
33. What is duck typing?
Answer:
Duck typing focuses on behavior rather than the actual type. βIf it walks like a duck and quacks like a duck, it’s a duck.β
34. Explain the use of super().
Answer:super() is used to call a method from a parent class in child classes, especially in multiple inheritance.
35. What are frozensets?
Answer:frozenset is an immutable version of a set. It cannot be modified once created and is hashable (can be used as dict keys).
36. What is the use of globals() and locals()?
Answer:
-
globals()returns a dictionary of global scope. -
locals()returns a dictionary of the current local symbol table.
37. How do you use list and dictionary comprehensions?
Answer:
List and dictionary comprehensions provide a compact way to create collections.
38. Explain try...except...else...finally.
Answer:
-
try: Run the code. -
except: Handle exceptions. -
else: Runs if no exception. -
finally: Always runs.
39. Are arguments passed by value or reference in Python?
Answer:
Python uses pass-by-object-reference. Mutable objects (like lists) can be changed, while immutable (like ints, strings) cannot.
40. Difference between iterator and iterable?
Answer:
-
Iterable: An object that can return an iterator (e.g., list, tuple).
-
Iterator: Object with
__next__()and__iter__()methods.

![Python intermediate interview questions [Updated] python basic interview questions](https://www.kaashivinfotech.com/blog/wp-content/uploads/2023/12/Basic-Python-Interview-Questions-Answers-150x150.png)