Krazy Kaksha

Interview Prep

Top 40 Python Interview Questions and Answers for Freshers (2026)

Krazy Kaksha 8 min read

Top 40 Python Interview Questions and Answers for Freshers (2026)

Python is the most asked language in fresher interviews today, from service companies to startups and data roles. The good news: interviewers mostly ask the same 40 or so questions again and again. If you can answer these in simple words, with a small example, you will clear the Python round.

Each answer below is short on purpose. Say it in your own words in the interview, then give the example.

Quick summary

SectionWhat it covers
Basics (Q1 to Q10)What Python is, data types, mutable vs immutable, PEP 8
Data structures (Q11 to Q18)List, tuple, set, dictionary, slicing, comprehension
Functions (Q19 to Q26)args, kwargs, lambda, scope, decorators, generators
OOP (Q27 to Q33)Class, self, init, inheritance, dunder methods
Advanced (Q34 to Q37)Memory, GIL, exceptions, shallow vs deep copy
Coding tasks (Q38 to Q40)Reverse a string, palindrome, find duplicates

Python basics

1. What is Python?
Python is a high-level, interpreted, general-purpose programming language. It is easy to read, dynamically typed and supports procedural, object-oriented and functional styles.

2. What are the key features of Python?

  • Simple and readable syntax
  • Interpreted (runs line by line)
  • Dynamically typed (no need to declare types)
  • Huge standard library and community packages
  • Portable across Windows, Linux and macOS

3. Is Python compiled or interpreted?
Both, in a way. Python source code is first compiled to bytecode (.pyc files), and then the Python Virtual Machine interprets that bytecode. In interviews, the simple answer is “interpreted”.

4. What are Python’s built-in data types?

CategoryTypes
Numbersint, float, complex
Textstr
Sequencelist, tuple, range
Mappingdict
Setset, frozenset
Booleanbool
NoneNoneType

5. What is the difference between mutable and immutable objects?
Mutable objects can be changed after creation (list, dict, set). Immutable objects cannot be changed (int, float, str, tuple). If you “change” a string, Python actually creates a new string.

6. What is dynamic typing?
The type of a variable is decided at run time by the value you assign. x = 5 makes x an int, and later x = "hi" makes it a str.

7. What is PEP 8?
PEP 8 is the official style guide for Python code. It covers naming, indentation (4 spaces), line length and spacing so that everyone’s code looks clean and consistent.

8. What is indentation in Python and why is it important?
Python uses indentation (spaces at the start of a line) to define blocks of code instead of curly braces. Wrong indentation gives an IndentationError.

9. What is the difference between == and is?
== checks if two values are equal. is checks if two variables point to the same object in memory.

10. What are break, continue and pass?

  • break exits the loop.
  • continue skips to the next loop iteration.
  • pass does nothing; it is a placeholder where a statement is required.

Data structures

11. What is the difference between a list and a tuple?

ListTuple
MutableImmutable
Square brackets [1, 2]Round brackets (1, 2)
Slightly slowerSlightly faster
Cannot be a dictionary keyCan be a dictionary key

12. What is a dictionary?
A dictionary stores data as key: value pairs. Keys must be unique and immutable. Example: student = {"name": "Riya", "marks": 88}.

13. What is a set?
A set is an unordered collection of unique items. It is useful to remove duplicates: set([1, 2, 2, 3]) gives {1, 2, 3}.

14. What is slicing?
Slicing takes a part of a sequence using [start:stop:step]. Example: "python"[0:3] gives "pyt", and s[::-1] reverses a string.

15. What is list comprehension?
A short way to create a list in one line. Example: squares = [x*x for x in range(5)] gives [0, 1, 4, 9, 16].

16. What is the difference between append() and extend()?
append() adds one item (even a whole list as one item). extend() adds each item of another iterable one by one.

17. What is the difference between remove(), pop() and del?

  • remove(x) deletes the first matching value.
  • pop(i) deletes by index and returns the item.
  • del list[i] deletes by index (or a slice) and returns nothing.

18. How do you sort a list?
my_list.sort() sorts the list in place. sorted(my_list) returns a new sorted list and keeps the original unchanged.

Functions

19. What are *args and kwargs?**
*args collects extra positional arguments as a tuple. **kwargs collects extra keyword arguments as a dictionary. They let a function accept any number of inputs.

20. What is a lambda function?
A small anonymous function written in one line. Example: add = lambda a, b: a + b. It is often used with map(), filter() and sorted().

21. What do map(), filter() and reduce() do?

  • map() applies a function to every item.
  • filter() keeps items where the function returns True.
  • reduce() (from functools) combines all items into one value.

22. What is the LEGB rule?
It is the order in which Python looks up a variable name: Local, Enclosing, Global, Built-in.

23. What is the difference between global and nonlocal?
global lets a function change a variable defined at module level. nonlocal lets an inner function change a variable of its enclosing function.

24. What is a decorator?
A decorator is a function that takes another function, adds some behaviour and returns it, without changing the original code. It is written with @decorator_name above a function. Common uses: logging, timing, login checks.

25. What is a generator?
A generator is a function that uses yield to return values one at a time. It saves memory because it does not create the whole list at once. Good for large files or infinite sequences.

26. What is the difference between an iterator and an iterable?
An iterable is anything you can loop over (list, string). An iterator is the object that gives the next value with next(). You get an iterator from an iterable using iter().

Object-oriented programming

27. What is a class and an object?
A class is a blueprint. An object is a real instance made from that blueprint. Example: Car is a class, my_car = Car() is an object.

28. What is self?
self refers to the current object. It is the first parameter of instance methods and is used to access the object’s variables and methods.

29. What is __init__?
__init__ is the constructor method. It runs automatically when an object is created and is used to set initial values.

30. What types of inheritance does Python support?
Single, multiple, multilevel, hierarchical and hybrid inheritance. Python supports multiple inheritance, which Java does not support with classes.

31. What is MRO?
Method Resolution Order is the order in which Python searches parent classes for a method, important in multiple inheritance. You can see it with ClassName.__mro__.

32. What are dunder (magic) methods?
Methods with double underscores like __init__, __str__, __len__ and __add__. They let your objects work with built-in operations such as print(), len() and +.

33. What is the difference between @staticmethod and @classmethod?
A static method gets no automatic first argument. A class method gets the class (cls) as the first argument and can create or change class-level data.

For more OOP theory, read our OOPs interview questions.

Advanced questions

34. How is memory managed in Python?
Python uses a private heap. Memory is freed mainly by reference counting, and a garbage collector cleans up objects that refer to each other in cycles.

35. What is the GIL?
The Global Interpreter Lock allows only one thread to run Python bytecode at a time in CPython. So threads help for I/O tasks, but for CPU-heavy work people use multiprocessing.

36. How does exception handling work?
Use try for risky code, except to handle the error, else for code that runs if there was no error and finally for code that always runs (like closing a file).

37. What is the difference between shallow copy and deep copy?
A shallow copy (copy.copy()) copies the outer object but shares inner objects. A deep copy (copy.deepcopy()) copies everything, so changes in the copy never affect the original.

Coding questions

38. Reverse a string.
s[::-1] returns the reversed string. You can also explain a loop version to show logic.

39. Check if a string is a palindrome.
Clean the string, then compare: s == s[::-1]. Example: “madam” returns True.

40. Find duplicates in a list.
Loop through the list and keep a set of seen items. If an item is already in the set, it is a duplicate. This runs in O(n) time.

Practise SQL too, since most Python roles also test queries: SQL interview questions.

How to prepare in 3 days

DayFocus
Day 1Q1 to Q18: basics and data structures, write small examples
Day 2Q19 to Q37: functions, OOP and advanced topics
Day 3Coding tasks, 10 easy problems, and mock answers out loud

Also revise Java interview questions if your company asks for a second language, and try our placement puzzles for the aptitude round.

Free study material

Free notes and Unit 1 of every eBook are on our Study Material page.

Doubts? Ask here

Leave a comment

Your email is not shown. Comments appear after a quick check.