Python Interview Questions for Freshers (2026): 35 Questions with Clear Answers
- Home
- Blog
- Full Stack & Programming
- Python Interview Questions for Freshers (2026): 35 Questions with Clear Answers
Short answer: fresher Python interviews focus on core concepts you use every day: data types and mutability (list vs tuple vs set vs dictionary), how functions and arguments work, object-oriented programming, exception handling, comprehensions, and generators and decorators. Expect two or three small coding tasks, such as reversing a string, counting word frequency or removing duplicates, and questions about your projects. The answers below are short enough to say aloud, with code where it helps.
If you are still learning the language, start with why Python is a great first language and build something from our Python projects for beginners list. Interviewers ask about projects as much as theory.
Python basics
1. What is Python and why is it popular?
Python is a high-level, interpreted, dynamically typed, general-purpose language with readable syntax and a huge standard library and ecosystem. It is popular for web development (Django, Flask, FastAPI), data analysis (pandas, NumPy), machine learning and AI, automation and testing.
2. Is Python compiled or interpreted?
Both, in a sense. CPython, the standard implementation, compiles source code to bytecode (.pyc files), which the Python virtual machine then interprets. You do not run a separate compile step yourself.
3. What does dynamically typed mean?
Types belong to values, not variables, and are checked at run time. The same variable can hold an integer and later a string. Type hints such as def add(a: int, b: int) -> int document intent and help tools, but Python does not enforce them at run time.
4. What is PEP 8?
Python’s official style guide: four-space indentation, snake_case for functions and variables, PascalCase for classes, and readable line lengths. Tools such as Black, Ruff or Flake8 help enforce it.
5. What is the difference between == and is?
== compares values. is checks whether two names point to the same object in memory. Use is only for singletons such as None: if x is None.
Data types and mutability
6. What are Python’s built-in data types?
Numbers (int, float, complex), bool, str, and the collections list, tuple, set, frozenset and dict, plus None.
7. What is the difference between list, tuple, set and dictionary?
| Type | Ordered | Mutable | Duplicates | Typical use |
|---|---|---|---|---|
| list | Yes | Yes | Allowed | Sequences you change: [1, 2, 3] |
| tuple | Yes | No | Allowed | Fixed records, dictionary keys: (19.07, 72.87) |
| set | No | Yes | Not allowed | Unique items, fast membership tests: {1, 2} |
| dict | Keeps insertion order | Yes | Unique keys | Key–value lookups: {"name": "Asha"} |
8. What is the difference between mutable and immutable objects?
Mutable objects (list, dict, set) can be changed in place. Immutable objects (int, float, str, tuple) cannot; “changing” them creates a new object. Only immutable (hashable) objects can be dictionary keys or set members.
9. What is the difference between a shallow copy and a deep copy?
A shallow copy (list.copy(), copy.copy()) creates a new outer object but shares the nested objects. A deep copy (copy.deepcopy()) copies everything recursively, so changing a nested list in the copy does not affect the original.
10. How do slicing and negative indexes work?
s[start:stop:step] returns items from start up to but not including stop. Negative indexes count from the end: s[-1] is the last item and s[::-1] reverses a sequence.
11. What are list, dictionary and set comprehensions?
squares = [n * n for n in range(10) if n % 2 == 0]
lengths = {word: len(word) for word in ["sql", "python"]}
unique_chars = {ch for ch in "mississippi"}
Functions
12. What are *args and **kwargs?
*args collects extra positional arguments into a tuple, and **kwargs collects extra keyword arguments into a dictionary. They let a function accept a flexible number of arguments.
13. What is the mutable default argument problem?
Default values are created once, when the function is defined. A default list is shared between calls:
def add_item(item, items=None): # correct pattern
if items is None:
items = []
items.append(item)
return items
14. What is a lambda function?
A small anonymous function written in one expression, often used as a key or callback: sorted(students, key=lambda s: s["marks"]).
15. What do map, filter and zip do?
map applies a function to each item, filter keeps items for which a function returns true, and zip pairs items from several iterables. Comprehensions are often clearer than map and filter.
16. What is scope and the LEGB rule?
Python looks up names in Local, Enclosing, Global and Built-in scope, in that order. Use global or nonlocal only when you must rebind a variable from an outer scope.
17. How are arguments passed in Python?
By object reference (sometimes called “pass by assignment”). The function receives a reference to the same object, so changes to a mutable argument are visible to the caller, but rebinding the parameter name is not.
Object-oriented programming
18. What are classes and objects?
A class is a blueprint that defines attributes and methods. An object is an instance of a class. __init__ initialises each new object, and self refers to the current instance.
19. Explain the four pillars of OOP in Python.
Encapsulation (bundling data and methods, with a leading underscore signalling “internal”), inheritance (a class reusing another’s behaviour), polymorphism (the same method name behaving differently per class) and abstraction (exposing what an object does, often with abstract base classes from abc).
20. What is the difference between instance, class and static methods?
Instance methods take self and work with one object. @classmethod takes cls and is often used for alternative constructors. @staticmethod takes neither and is a plain function grouped inside the class.
21. What are dunder (magic) methods?
Special methods with double underscores that customise behaviour: __str__ for readable printing, __repr__ for debugging, __len__, __eq__, __add__ and so on.
22. Does Python support multiple inheritance?
Yes. Python resolves which parent’s method to use with the method resolution order (MRO), which you can inspect with ClassName.__mro__.
Exceptions and files
23. How does exception handling work?
try:
value = int(user_input)
except ValueError:
print("Please enter a number")
else:
print("You entered", value) # runs only if no exception
finally:
print("Done") # always runs
24. How do you create a custom exception?
Subclass Exception: class InsufficientBalanceError(Exception): pass, then raise InsufficientBalanceError("Balance too low").
25. Why use with when opening files?
The with statement uses a context manager that closes the file automatically, even if an error occurs: with open("data.csv") as f:.
Iterators, generators and decorators
26. What is the difference between an iterable and an iterator?
An iterable (list, string, dict) can return an iterator with iter(). An iterator produces values one at a time with next() and remembers its position.
27. What is a generator?
A function that uses yield to produce values lazily, one at a time, instead of building a whole list in memory. It is ideal for large files or streams. Generator expressions look like comprehensions with parentheses: (n * n for n in range(10**6)).
28. What is a decorator?
A function that wraps another function to add behaviour without changing its code, such as logging, timing or access checks.
import functools, time
def timer(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.perf_counter()
result = func(*args, **kwargs)
print(f"{func.__name__} took {time.perf_counter() - start:.3f}s")
return result
return wrapper
29. What is the GIL?
The Global Interpreter Lock in CPython lets only one thread execute Python bytecode at a time, so threads help with I/O-bound work (network, files) but not CPU-bound work. For CPU-heavy tasks use multiprocessing. Recent Python versions also offer an optional free-threaded build without the GIL.
30. What are modules, packages and virtual environments?
A module is a .py file, and a package is a folder of modules. A virtual environment (python -m venv .venv) isolates each project’s dependencies, which you install with pip and list in requirements.txt.
Coding questions
31. Reverse a string and check for a palindrome.
def is_palindrome(text):
cleaned = "".join(ch.lower() for ch in text if ch.isalnum())
return cleaned == cleaned[::-1]
32. Count word frequency in a sentence.
from collections import Counter
counts = Counter("the cat and the hat".split())
print(counts.most_common(2)) # [('the', 2), ('cat', 1)]
33. Remove duplicates while keeping order.
list(dict.fromkeys(items)) works because dictionaries keep insertion order.
34. Find the second largest number in a list.
def second_largest(nums):
unique = sorted(set(nums))
return unique[-2] if len(unique) >= 2 else None
35. Print the first n Fibonacci numbers.
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
print(list(fibonacci(8))) # [0, 1, 1, 2, 3, 5, 8, 13]
How to prepare
- Write every answer above as code in a notebook or editor, not just in your head.
- Solve 30 to 50 easy problems on strings, lists and dictionaries, and state the time complexity of your solution. Our guide to how much DSA you need for placements sets sensible targets.
- Prepare a two-minute walkthrough of one project: the problem, your design, libraries used and one bug you fixed.
- Add the libraries your target role uses: pandas and SQL for data roles, Django or FastAPI for web roles, pytest or Selenium for testing roles. For data roles, also revise our SQL interview questions.
See the full process in our tech interview preparation guide.
Learn Python at TryCatch Classes
TryCatch Classes’ Python Training covers Python fundamentals, control flow, functions, OOP, file handling, error handling and debugging, advanced Python such as comprehensions and lambda functions, regular expressions, REST APIs, web scraping and desktop apps with Tkinter, with 15+ projects. To build web applications too, see Python Full Stack. Learn at our Borivali West classroom or live online, with a 100% placement guarantee.
A note from Mehul Prajapati, Founder, TryCatch Classes
I have spent 18+ years in IT and training and have personally mentored 12,000+ students. If you are planning your next step in Python and want a second opinion on your learning path, I am happy to help.
“The technology you learn today may change tomorrow, but your ability to learn will always be your biggest strength. Stay curious, keep upgrading yourself, and never stop growing.”
Message me on WhatsApp at +91 99301 12627 and tell me which blog you read. I would love to hear from you.
Frequently asked questions
Is Python enough to get a job as a fresher?
Python alone rarely is. Pair it with a direction: SQL and pandas for data roles, Django or FastAPI plus databases for web roles, or Selenium and pytest for testing roles, and show two or three projects.
Which Python topics are asked most in fresher interviews?
Data types and mutability, list vs tuple vs dictionary, functions and *args/**kwargs, OOP, exception handling, comprehensions, generators and decorators, plus short coding tasks.
Do interviewers ask Python version questions?
Rarely in detail. You should know you are using Python 3 and be aware of useful modern features such as f-strings, type hints and dataclasses.
How long does it take to prepare for a Python interview?
With basic knowledge in place, two to four weeks of daily coding practice and revision is usually enough for fresher-level interviews.
Cover image: photo by Ilya Pavlov on Unsplash.
Keep reading
Full Stack & ProgrammingPython Developer Roadmap for Freshers (2026): Basics to a Job-Ready PathA step-by-step Python developer roadmap for freshers: the basics, functions and data structures, OOP, files and errors, the package ecosystem, then choosing a direction (web, data/AI…Full Stack & ProgrammingJava Developer Roadmap for Freshers (2026): Core Java to Spring BootFull Stack & ProgrammingGit and GitHub for Beginners (2026): Commands, Workflow and First Steps← Previous articleCyber Security Interview Questions for Freshers (2026): 40 Questions with AnswersNext article →Java Interview Questions for Freshers (2026): 40 Questions with Clear Answers
