Crack Python Interviews With Confidence
20 real
20 real interview
interview questions
questions -- verified,
verified, solved,
solved, and
and explained
explained
From real interviews at Infosys, Wipro, Cognizant,
Deloitte, Microsoft and more
Created by Naveen Dhawan
EASY (Fundamentals)
1) What is the difference between a list and a
tuple in Python? Infosys
A: List = Mutable, Slower, Uses [], Data can change.
Tuple = Immutable, Faster, Uses (), Data stays constant.
2) What are the key features of Python?
HARMAN
A: Python is:
Interpreted and dynamically typed
Easy to read, write, and learn
Open-source and cross-platform
Supports multiple programming paradigms
Rich in libraries and frameworks
3) What is the difference between the ‘==’
operator and the ‘is’ operator in Python?
Infosys
A: We use “==” to check whether two objects have the
same value (content equality).
We use “is” to check whether two references point to
the same object in memory (identity).
list = [10, 20]
list == list[:] #True - same values
list is list[:] #False - different ojects in memory
4) Could you explain list comprehension and
write examples? Infosys
A: List comprehension lets you create a new list in a short,
clean, single-line expression.
5) What are mutable vs. immutable data types
in Python? (e.g. why a tuple is immutable, a
list isn’t) Cognizant
A: Mutable types can be changed after creation (e.g., list,
dict, set).
Immutable types cannot be changed; any update
creates a new object (e.g., tuple, string, int).
Why is “tuple” immutable? - Because its structure is fixed.
Why is “list” mutable? - Because it is designed to allow
adding or modifying items.
6) How to reverse a number, string conversions
in Python? Cognizant
A: To reverse a number, convert it to a string, reverse the
string, and convert it back to a number.
To reverse a string, use slicing ([::-1]) to reverse the
characters.
7) What are Python decorators? Infosys
A: Python decorators are functions that modify or extend the
behaviour of other functions without changing their actual
code.
8) How do you sort a list in Python? Infosys
A: Sorting a list means arranging its elements in order.
In Python, you can use sort() to sort the list itself or
sorted() to get a new sorted list.
9) How do you separate text and numbers from
a mixed string? Infosys
A: To separate letters and numbers from a string, iterate
through each character and use isalpha() for letters and
isdigit() for numbers.
Python Interview Questions | Created by Naveen Dhawan
10) What is PEP 8, and why is it important?
Barclays
A: PEP 8 is the official Python Style Guide that defines best
practices for writing clean, readable, and consistent code.
Example rule: Use 4 spaces per indentation level.
11) What is the difference between break,
continue, and pass? Wipro
A: break → Exits the loop completely.
continue → Skips the current iteration and moves to
the next one.
pass → Does nothing; used as a placeholder in code.
12) What is a lambda function? Deloitte
A: A lambda function is an anonymous, one-line function
used for simple, short operations. It doesn’t need a
name and is often used for short, throwaway
functions.
MEDIUM (Intermediate)
1) Explain list slicing with examples.
Tech Mahindra
A: List slicing is used to access a subset of elements from a list
using the [start:stop:step] syntax.
2) What is the difference between deepcopy and
shallow copy? SAP
A: Shallow Copy: Creates a new object but only copies
references to nested objects. Changes in nested objects
affect the original.
Example: b = [Link]()
Deep Copy: Creates a completely independent copy,
including all nested objects. Changes do not affect the
original.
Python Interview Questions | Created by Naveen Dhawan
3) How do you print all permutations of a string
in Python? Microsoft
A: You can generate permutations using recursion, where you
fix one character at a time and permute the rest.
4) How do you count the number of vowels in a
string in Python? Deloitte
A:
5) How do you check if a string is a palindrome
in Python? Deloitte
A: A palindrome is a string that reads the same forward and
backward.
6) Write a Python program to print all prime
numbers between 1 and 100. Cognizant
A:
7) Write a Python program to count how many
times each character appears in the string
"Data Analysis". Wipro
A:
8) Given a nested list [[1,2], [3,4], [[4], [6]]], write
a Python program to flatten it into a single
list: [1,2,3,4,4,6]. Wipro
Your turn to solve this one — try it out!
Python Interview Questions | Created by Naveen Dhawan