Top 20 Interview Python Questions

 

Top 20 Interview Python Questions


1. What will be the output of the following code?

python
x = [1, 2, 3, 4] print(x[-1])

a) 1
b) 4
c) Error
d) None

Answer: b) 4


2. What is the output of the following code?

python
print(bool(0), bool(3.14), bool(''))

a) True True False
b) False True False
c) False True True
d) True False False

Answer: b) False True False


3. What does the len() function do in Python?

a) Returns the number of elements in a list or string
b) Checks if a list is empty
c) Computes the length of an integer
d) None of the mentioned

Answer: a) Returns the number of elements in a list or string


4. What will the following code output?

python
list1 = [1, 2, 3, 4] print(list1[1:3])

a) [1, 2]
b) [2, 3]
c) [1, 2, 3]
d) Error

Answer: b) [2, 3]


5. Which of the following is a mutable data type in Python?

a) String
b) Tuple
c) List
d) None of the mentioned

Answer: c) List


6. What will be the output of the following code?

python
x = "hello" print(x * 2)

a) hellohello
b) hello*2
c) Error
d) None

Answer: a) hellohello


7. What will be the output of the following code?

python
x = [1, 2, 3] x.append([4, 5]) print(len(x))

a) 4
b) 5
c) 6
d) Error

Answer: a) 4


8. What will be the output of the following code?

python
y = [1, 2, 3, 4] print(y.pop())

a) 1
b) 2
c) 3
d) 4

Answer: d) 4


9. What is the output of the following code?

python
print(type({}))

a) <class 'list'>
b) <class 'dict'>
c) <class 'set'>
d) <class 'tuple'>

Answer: b) <class 'dict'>


10. What will be the output of the following code?

python
for i in range(3, 10, 3): print(i, end=" ")

a) 3 6 9
b) 3 6
c) 4 7
d) Error

Answer: b) 3 6


11. What is the correct syntax to define a function in Python?

a) def functionName():
b) function functionName():
c) define functionName():
d) functionName define():

Answer: a) def functionName():


12. What is the output of the following code?

python
print(2 ** 3 ** 2)

a) 64
b) 512
c) 8
d) 256

Answer: b) 512


13. What is the output of the following code?

python
x = "Python" print(x[1:-1])

a) Pytho
b) ytho
c) Pyth
d) Error

Answer: b) ytho


14. What is the data type of None in Python?

a) int
b) float
c) bool
d) NoneType

Answer: d) NoneType


15. Which of the following statements is correct about Python?

a) Python is a compiled language
b) Python is an interpreted language
c) Python is both compiled and interpreted
d) None of the mentioned

Answer: b) Python is an interpreted language


16. What will be the output of the following code?

python

x = [1, 2, 3] print(x * 2)

a) [1, 2, 3, 1, 2, 3]
b) [1, 2, 3, 2]
c) Error
d) None

Answer: a) [1, 2, 3, 1, 2, 3]


17. What is the output of the following code?

python
list1 = [1, 2, 3] list2 = list1 list1.append(4) print(list2)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) Error
d) None

Answer: b) [1, 2, 3, 4]


18. What is the output of the following code?

python

x = {'a': 1, 'b': 2} print(x.get('c', 3))

a) None
b) 3
c) Error
d) KeyError

Answer: b) 3


19. What is the output of the following code?

python

x = 10 print('Yes' if x % 2 == 0 else 'No')

a) Yes
b) No
c) Error
d) None

Answer: a) Yes


20. What will be the output of the following code?

python

print(",".join(['a', 'b', 'c']))

a) 'a b c'
b) 'abc'
c) 'a,b,c'
d) Error

Answer: c) a,b,c

Top 20 Interview Python Questions Top 20 Interview Python Questions Reviewed by Shubham Prajapati on November 20, 2024 Rating: 5

No comments:

If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat

Powered by Blogger.