Press "Enter" to skip to content

Top 40 Commonly Python Interview Questions and Answers

Robert Wagner (Information Technology) 0

In this article, the tech learn has listed out Python Interview Questions and Answers asked by Every Interviewer. After going through each and every question, you will be fully prepared to go for Python interview

Python Interview Questions For Freshers

Q. 1. What is Python Programming language?

Python is a most demanding programming language with threads, objects, automatic memory management, modules and exceptions. Python is very easy, extensible, portable and an open source programming language.

Q. 2. What do you mean by PEP 8?

PEP 8 is a coding agreement, a set of reference about how to make a python code more readable.

Q. 3. Differentiate between list and tuple?

The major difference between list and tuple is as follow:
• List is mutable whereas tuple is not mutable.
• We can hash the Tuple but list cannot be hashed.

Q. 4. What are the supported data types in Python?

There are standard data types in Python −
• Dictionary
• List
• String
• Tuple
• Numbers

Q. 5. What is lambda in Python?

Lambada in Python is a single expression unidentified function which is usually used as an inline function.

Q. 6. What do you mean by namespace in Python?

Namespace in Python is a naming system which is especially used for making the names unique for avoiding the naming problems.

python interview questions about Namespace

Q. 7. Write some usually used built-in modules in Python?

Some of the usually used built-in modules are listed below:
• math
• Os
• data time
• random
• sys

Q. 8. What are Dict and List comprehensions?

Dict and list comprehensions are basically syntax constructions for making the formation of dictionary easier.

Q. 9. What are the key features of Python?

Main features of Python are:
• Dynamically-typed
• Free
• Object-oriented
• Has a large community
• Short and simple
• Interpreted

Q. 10. Explain how to delete a file in Python?

For deleting a file in Python we use a command: os.remove (filename) or os.unlink(filename).

Python Coding Interview Questions For Freshers

Q. 11. What is the following function inserts an object at given index in a list?

A – list.index(obj)
B – list.insert(index, obj)
C – list.pop(obj=list[-1])
D – list.remove(obj)
Correct – B

Q. 12. Which of the following variable is invalid?

(A) str
(B) _str
(C) _str
(D) None of these
Correct D

Q. 13. What gets printed?


A) new line then the string: c:newtodayabc.txt
B) the text exactly like this: r”c:\new\today\abc.txt”
c) the text like exactly like this: c:\new\today\abc.txt
D) the letter r and then newline then the text: c:\new\today\abc.txt
Correct C

Q. 14. What gets printed?

def f(): 

A) <class 'function'>
B) <class 'tuple'>
C) <class 'NoneType'>
D) <class 'str'>

Correct A

Q. 15. Code Solve

x = 4.5
y = 2

Correct A

Q. 16. What is output of the program?

value = 770
    value = value 
except ZeroDivisionError: 
    print('Cannot divide by 0 ', end = '') 
    print('Division successful ', end = '') 
    value = value /5.5
    print('Inside except block ', end = '') 
    print('Cannot execute simmultaneously', end = '')

a) Cannot divide by 0 Cannot execute simmultaneously
b) Cannot divide by 0
c) Division successful Cannot execute simmultaneouslyInside except block Cannot execute simmultaneously
d) Cannot divide by 0 Inside except block
Correct – C

Q. 17. what is output of the program?

def calculateSq(n):
    return n*n+n
numbers = (2, 3, 4, 5)
result = list(map( calculateSq, numbers))

a) [2,3,4,5]
b) [4,6,8,10]
c) [4, 9, 16, 25]
d) [6, 12, 20, 30]
Correct: d

18. what is output of the program?

x = [‘ab’, ‘cd’]
print(len(list(map(list, x))))

a) 1
b) 2
c) len
d) None of these
correct: B

Q. 19. What is output of the program?

def fun(string):
    s1 = string
    s = string[::-1]
    if(s1 == s):
        return True
        return False


a) Error
b) False
c) True
d) madam

Q. 20. What is output of the program?

def sum(num):
	if len(num) == 1:
		return num[0]            	
		return num[0] + sum(num[1:])
print(sum([2, 4, 5, 6, 7]))

a) 2
b) 24567
c) 6
d) 24
correct: D

Python Interview Questions for Experienced

Q. 21. What are functions in Python?

Function in Python is a block of code which is performed when we call it to execute. For defining a function in Python, we use def keyword.

Q. 22. List of commonly used Immutable built-in datatypes of Python?

Usually used Immutable built-in datatypes of Python are:
• Numbers
• Strings
• Tuples

Q. 23. When do we used the Python decorator?

Usually used Mutable built-in datatypes of Python are:
• List
• Dictionaries
• Sets

Q. 24. When do we used the Python decorator?

A relative change which we perform in the Python syntax for adjusting the functions rapidly.

Q. 25. What are some basic types of functions available in Python?

Two types of basic functions available in Python which are listed below:
• Built-in function
• User-defined function

Q. 26. What is pickling?

Any Python objects are accepted and converted into string representation by the Pickle module which uses dump function for dumping it into a file and the whole process is called pickling.

Q. 27. What are Python decorators?

A Python decorator is a particular change which we apply in Python syntax for altering the functions simply.

Q. 28. What are the ways for applying reverse string?

There are five ways for applying the reverse string –
• Recursion
• Loop
• Reversed
• Extended Slice Syntax
• Stack

Q. 29. What is monkey patching?

Dynamic modifications of a module or a class during the run-time is known as monkey patch.

Q. 30. Does Python supports multiple inheritances?

Yes, Python supports multiple inheritances. A class can be originated from many parent classes.

Python Coding Interview Questions for Experienced

Q. 31. Import re

p = re.compile('\d') 
print(p.findall("I went to him at 11 A.M. on 4th July 1886"))

a) [‘1’, ‘1’, ‘4’, ‘1’, ‘8’, ‘8’, ‘6’]
b) [‘1′,’4′,’1′,’8′,’8′,’6’]
c) [‘1′,’1′,’4′,’1′,’8′,’8′,’6’]
d) None of the above
correct: A

Q. 32. Import re

print(re.split('[a-f]+', 'Aey, Boy oh boy, come here')) 

1) [‘On ‘, ‘th Jan 2016, at 11:02 AM’]
2) [”, ‘y, ‘, ‘oy oh ‘, ‘oy, ‘, ‘om’, ‘ h’, ‘r’, ”]
3) [‘A’, ‘y, Boy oh ‘, ‘oy, ‘, ‘om’, ‘ h’, ‘r’, ”]
4) none of these
Correct: 3

Q. 33. _ represents an entity in the real world with its identity and behaviour.

a) A method
b) An object
c) A class
d) An operator
correct :b

Q. 34. What is the output?

y= 6
z = lambda x: x * y
print z(8)

a) 48
b) 14
c) 64
d) None of the mentioned
Correct: A

Q. 35. To open a file c:\scores.txt for reading, we use

a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\scores.txt”, “r”)
correct: B

Q. 36. Class Test:

def __init__(self):
        print('no-args passed')
    def __init__(self,x):


a) no-args passed
b) no-args
c) Error
d) no-args 10
Correct: C

Q. 37. When will the else part of try-except-else be executed?

a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block
correct: C

Q. 38. Which is the correct operator for power(x^y)?

a) X^y
b) X**y
c) X^^y
d) None of the mentioned
Correct: B

Q. 39. What is the return type of function id?

A) floor
B) bool
C) dict
D) int
Correct – D

Q. 40. Which of the following is an invalid statement?

(A) abc = 1,000,000
(B) a b c = 1000 2000 3000
(C) a,b,c = 1000, 2000, 3000
(D) a_b_c = 1,000,000
Correct – C

The Tech Learn shares Python Interview questions and answers on regular basis as per the latest technology demands so if you are a job seeker and a technology lover the keep visiting us.

Reference Link:

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *