Python interview questions ✅
Python interview questions ✅
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.
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
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.
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.
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.
09
Q 18. What are Python packages?
Ans: Python packages are namespaces containing
multiple modules.
11
Q 23. How is OOPS used in Python?
Ans: OOPS is a paradigm in Python that uses classes
and objects.
12
Q 26. Does python support multiple inheritance?
Ans: Multiple inheritance means that a class can be
derived from more than one parent classes.
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.
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.
Python
15
Q 35. Differentiate between HAVING and
A2 = sorted([i for i in A1 if i in
A0.values()])
A5 = {i: i*i for i in A1}
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)
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.")
18
Our students have gone on to work at renowned companies,
innovative startups, and leading unicorns.
Crack Project
Job
Top
MNC’s
Updates
Courses Blogs
E - Books
www.thelearnnova.com Follow us -