Python Interview Questions
Python is one of the most-tested languages in technical interviews, from freshers to senior roles. These are the questions that come up again and again, with concise answers you can explain confidently.
16 questions with concise, interview-ready answers.
1. What are the key features of Python?
Python is a high-level, interpreted, dynamically typed and garbage-collected language with a large standard library ("batteries included"). It supports multiple paradigms — object-oriented, functional, and procedural — and emphasizes readable, concise code.
2. What is the difference between a list and a tuple?
Lists are mutable and use more memory; tuples are immutable, hashable (so they can be dictionary keys), and slightly faster. Use a tuple for fixed collections and a list when the data changes.
3. What is the difference between "is" and "=="?
== compares values for equality, while "is" compares identity — whether two names point to the exact same object in memory. For example, two equal lists are == but not "is".
4. What are list comprehensions?
A concise syntax for building a list from an iterable, optionally with a condition: [x*x for x in range(10) if x % 2 == 0]. They are usually more readable and faster than an equivalent for-loop with append.
5. What is the difference between a shallow copy and a deep copy?
A shallow copy (copy.copy) duplicates the outer object but shares references to nested objects. A deep copy (copy.deepcopy) recursively duplicates everything, so changes to nested data do not affect the original.
6. What are *args and **kwargs?
*args collects any extra positional arguments into a tuple, and **kwargs collects extra keyword arguments into a dictionary. They let a function accept a variable number of arguments.
7. What is a decorator in Python?
A decorator is a function that takes another function (or class) and returns a modified version, applied with the @decorator syntax. It is used to add behavior — logging, authentication, caching, timing — without changing the original code.
8. What is the GIL (Global Interpreter Lock)?
The GIL is a mutex in CPython that allows only one thread to execute Python bytecode at a time. It simplifies memory management but limits CPU-bound multithreading; use multiprocessing or async I/O for true parallelism.
9. What are generators and why use them?
Generators are functions that use yield to produce values lazily, one at a time, instead of building a full list in memory. They keep their state between calls, making them ideal for large or infinite sequences.
10. How is memory managed in Python?
Python uses reference counting to free objects when their count hits zero, plus a cyclic garbage collector to clean up reference cycles. All of this happens in a private heap managed by the Python memory manager.
11. What is the difference between a module and a package?
A module is a single .py file containing code. A package is a directory of modules (historically marked by an __init__.py file) that groups related modules under one namespace.
12. What is a lambda function?
A lambda is a small anonymous function limited to a single expression, e.g. lambda x: x + 1. It is handy for short callbacks such as the key in sorted() or map()/filter().
13. What is the difference between @staticmethod and @classmethod?
A staticmethod takes no implicit first argument and behaves like a plain function inside the class. A classmethod receives the class (cls) as its first argument and can read or modify class-level state, while a regular method receives the instance (self).
14. What does the "self" parameter do?
self is the conventional name for the first parameter of an instance method; it refers to the specific object the method is called on, giving access to that object's attributes and other methods.
15. What are Python's mutable and immutable types?
Immutable types include int, float, str, tuple, bool, and frozenset — their value cannot change after creation. Mutable types include list, dict, set, and most custom objects, which can be modified in place.
16. What is the difference between Python 2 and Python 3?
Python 3 made print a function, made division (/) return floats, uses Unicode strings by default, and removed legacy constructs like xrange. Python 2 reached end-of-life in 2020, so all new code should target Python 3.
Get these answered live in your real interview
NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.
Try NostrobeAI free