0% found this document useful (0 votes)
2 views20 pages

Python interview questions ✅

The document provides a comprehensive list of 40 commonly asked interview questions about Python, covering topics such as its definition, functions, data structures, OOP concepts, and practical coding examples. Key differences between Python 2 and 3, as well as the future of Python, are also discussed. Additionally, it includes explanations of various programming concepts like recursion, encapsulation, and generators.

Uploaded by

tharun leander
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Python interview questions ✅

The document provides a comprehensive list of 40 commonly asked interview questions about Python, covering topics such as its definition, functions, data structures, OOP concepts, and practical coding examples. Key differences between Python 2 and 3, as well as the future of Python, are also discussed. Additionally, it includes explanations of various programming concepts like recursion, encapsulation, and generators.

Uploaded by

tharun leander
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

MOST ASKED - 40

Interview Questions
Q 1. What is Python?
Ans: Python is a general-purpose computer
programming language based on object-
oriented programming. The programs in Python
can run equally on every operating system. It is
the primary language used in modern
technologies like AI, data science, and ML.
Q 2. Where to run Python code?
Ans: It can run a Python code from the run option in the
menu in an interpreter. A Python code can also run
in command prompt code.
Q 3.Python an interpreted language. Explain.
Ans: An interpreted language is any programming
language which is not in machine level code
before runtime. Therefore, Python is an
interpreted language.

01
Q 4. What is a function in Python with example?
Ans: A function is a block of reusable code that
performs a specific task. Functions help organize
code, make it reusable, and improve readability.

Q 5. What is the difference between list and


tuples in Python?
Ans: List Tuples

Tuples are immutable (tuples


Lists are mutable i.e they can be
are lists which can’t be
edited.
edited).

Lists are slower than tuples. Tuples are faster than list.

Syntax: list_1 = [10, ‘nova’, 20] Syntax: tup_1 = (10, ‘nova’ , 20)

02
Q 6. What is namespace in Python?
Ans: A namespace is a naming system used to
make sure that names are unique to avoid
naming conflicts.

Crack your
Dream Company
by LearnNova

Q 7. What is Python virtualenv?


Ans: virtualenv is an isolated environment used for
developing and debugging Python applications. It
allows multiple applications to run independently
by managing their own dependencies using pip. It
also isolates the Python interpreter, along with its
settings and installed libraries, from the global
environment.

03
Q 8. What do you think of the future of Python?
Ans: The future of Python is very promising. It's widely
used in AI, data science, web development, and
automation due to its simplicity and versatility.
With strong community support and increasing
adoption in education and industry.
Python will remain in high demand for years to
come.

Q 9.What are local variables and global variables


in Python?
Ans: Global Variables: Variables declared outside a
function or in global space are called global
variables. These variables can be accessed by
any function in the program.

Local Variables: Any variable declared inside a


function is known as a local variable. This variable
is present in the local space and not in the global
space.

04
Q 10. What is the Python dictionary?
Ans: A dictionary in Python is a collection of items that
are written in curly brackets with keys and values.
The items are in no particular order and are used
to retrieve the value for keys that are known.
Q 11.What are the basic applications of Python?
Ans:

05
Q 12. What is recursion in Python?
Ans: Recursion in Python is a programming technique
where a function calls itself within its own definition.
It's a powerful tool for solving problems that can be
broken down into smaller, self-similar subproblems.

06
Q 13. What are the differences between Python
2 and Python 3?
Ans: Python 2 and Python 3 differ mainly in syntax and
features.
In Python 2, the print statement is written without
parentheses (print "Hello"), while
in Python 3, it's a function (print("Hello")).
Python 2 performs integer division by default (e.g.,
5 / 2 = 2), but
Python 3 returns a float (5 / 2 = 2.5). Unicode
handling is better in Python 3, where strings are
Unicode by default.
Python 2 reached end of life in 2020 and is no
longer maintained, whereas
Python 3 is actively updated and widely
supported by modern libraries.

07
Q 14. What is the usage of help() and dir()
function in Python?
Ans: 1. Help() function: The help() function is used to
display the documentation string and also
facilitates you to see the help related to modules,
keywords, attributes, etc.

2. Dir() function: The dir() function is used to display


the defined symbols.

Q 15. What are the built-in types of python?


Ans: Built-in types in Python are as follows –
Integers
Floating-point
Complex numbers
Strings
Boolean
Built-in functions

08
Q 16. Whenever Python exits, why isn’t all the
memory de-allocated?
Ans: Python may not always deallocate objects with
circular references or those referenced globally
when it exits.
Memory reserved by the C library cannot be
freed by Python.
Python has an efficient cleanup mechanism
that attempts to deallocate all remaining
objects on exit.

Q 17. What are negative indexes and why are


they used?
Ans: negative indexes allow you to access elements
from the end of a list, string, or other sequences.
-1 refers to the last element.
-2 refers to the second-to-last element,

Negative indexes provide a convenient way to


access elements relative to the end of a
sequence without needing to calculate the
length of the sequence.

09
Q 18. What are Python packages?
Ans: Python packages are namespaces containing
multiple modules.

Q 19 . Does Python have OOps concepts?


Ans: Python is an object-oriented programming
language. This means that any program can be
solved in python by creating an object model.

Python can be treated as procedural as well as


structural language.

Q 20. What is the use of frozenset in Python?


Ans: A frozenset is an immutable set—meaning its
elements cannot be changed after creation. It is
used when you need a set that cannot be
modified, such as using it as a key in a dictionary
or storing it in another set.
10
Q 21. How is Multithreading achieved in Python?
Ans: Multithreading is achieved using the threading
module, which allows you to run multiple threads
(lightweight subprocesses) concurrently.

Q 22. How to import modules in python?


Ans: Modules can be imported using the import
keyword. You can import modules in three ways
import module_name
from module_name import function_name
import module_name as alias

11
Q 23. How is OOPS used in Python?
Ans: OOPS is a paradigm in Python that uses classes
and objects.

e.g - class, data abstraction, polymorphism,


inheritance, encapsulation, etc.

Q 24. What is encapsulation in Python?


Ans: Encapsulation is the process of hiding the
internal state of an object and requiring all
interactions to be performed through an object’s
methods.

Q 25. How are classes created in Python?


Ans: Class in Python is created using the class keyword.

12
Q 26. Does python support multiple inheritance?
Ans: Multiple inheritance means that a class can be
derived from more than one parent classes.

Python does support multiple inheritance

Q 27. What is inheritance in Python? Types ?


Ans: Inheritance is an object-oriented programming
(OOP) feature in Python that allows a class
(child/derived class) to inherit properties and
methods from another class (parent/base class).

13
Q 28. Define encapsulation in Python?
Ans: Encapsulation means binding the code and
the data together. A Python class in an
example of encapsulation.
Q 29. What does an object() do?
Ans: It returns a featureless object that is a base for all
classes.

It does not take any parameters.

Q 30. What is polymorphism in Python?


Ans: Polymorphism in python is something that is
used to describe the ability to take various
forms.

Q 31. Write a program in Python to check if a


sequence is a Palindrome.
Ans:
Python

s = input("Enter: ")
print("Palindrome" if s == s[::-1]
else "Not a palindrome")

14
Q 32. What is a lambda function?
Ans: An anonymous function is known as a lambda
function.
This function can have any number of
parameters but, can have just one statement.

Q 33. Write a sorting algorithm for a numerical


dataset in Python.
Ans: The following code can be used to sort a list in
Python

Python

numbers = ["1", "4", "0", "6", "9"]


numbers = sorted(int(i) for i in
numbers)
print(numbers)

Q 34. How good is Python for data analysis?


Ans: Python is very good for data analysis. Processes
like data mining, data processing, and data
visualization etc.

15
Q 35. Differentiate between HAVING and

Ans: These conditions are used for searching values


except that the HAVING clause is used with the
SELECT statement accompanied by the GROUP BY
clause. The HAVING clause is used in combination
with the GROUP BY clause to filter the data based
on aggregate values, while the WHERE clause is
used to filter the data based on individual values.

Q 36. Looking at the below code, write down the


final values of A0, A1, …An.
Ans:
Python

A0 = dict(zip('abcde', range(1, 6)))


A1 = range(10)

A2 = sorted([i for i in A1 if i in
A0.values()])
A5 = {i: i*i for i in A1}

print(A0, list(A1), A2, A5)

16
Q 37. Python code to find factorial of a number
Ans:
Python

def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)

num = int(input("Enter a number: "))


print(f"The factorial of {num} is
{factorial(num)}")

Q 38. Python code to reverse a string


Ans:
Python

def reverse_string(s):
return s[::-1]
text = input("Enter a string: ")
print("Reversed string: ",
reverse_string(text))

17
Q 39. Python code for Fibonacci series
Ans:
Python

def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
num = int(input("Enter a number: "))
if is_prime(num):
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")

Q 40. What are the generators in python?


Ans: Functions that return an iterable set of items
are called generators.

18
Our students have gone on to work at renowned companies,
innovative startups, and leading unicorns.

Explore our Programs

Crack Project
Job
Top
MNC’s
Updates

Resume LEARN Interview


Templates Questions
NOVA

Courses Blogs
E - Books

www.thelearnnova.com Follow us -

You might also like