Preparing for a Python interview can be daunting, especially when it comes to theoretical questions. Here are 20 multiple-choice questions that cover various aspects of Python. Test your knowledge and get ready to impress your interviewers!

1. What is the correct file extension for Python files?

  • A) .pyth
  • B) .python
  • C) .py
  • D) .p

Answer: C) .py


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

  • A) Tuple
  • B) String
  • C) List
  • D) Set

Answer: C) List


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

print(type([]) is list)
  • A) True
  • B) False
  • C) None
  • D) TypeError

Answer: A) True


4. Which built-in function can be used to read data from a file?

  • A) read()
  • B) open()
  • C) fileread()
  • D) file()

Answer: B) open()


5. What does the “len()” function do in Python?

  • A) Checks if an object is empty
  • B) Returns the number of items in an object
  • C) Returns the length of a string only
  • D) Counts characters in a sentence

Answer: B) Returns the number of items in an object


6. What is the output of the following code?

x = 'Python'
print(x[0:2])
  • A) Py
  • B) Python
  • C) P
  • D) yt

Answer: A) Py


7. Which of the following methods can be used to add an element to a list in Python?

  • A) add()
  • B) append()
  • C) insert()
  • D) Both B and C

Answer: D) Both B and C


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

print(bool(""))
  • A) True
  • B) False
  • C) None
  • D) TypeError

Answer: B) False


9. How is a dictionary defined in Python?

  • A) {key: value}
  • B) [key, value]
  • C) (key, value)
  • D) <key, value>

Answer: A) {key: value}


10. What keyword is used to create a function in Python?

  • A) function
  • B) def
  • C) func
  • D) define

Answer: B) def


11. Which operator is used for integer division in Python?

  • A) /
  • B) //
  • C) %
  • D) **

Answer: B) //


12. What type of error will be raised if you try to access a non-existing key in a dictionary?

  • A) KeyError
  • B) ValueError
  • C) TypeError
  • D) AttributeError

Answer: A) KeyError


13. What is the purpose of the ‘self’ parameter in Python class methods?

  • A) To refer to the current instance of the class
  • B) To refer to the class itself
  • C) To create a new class
  • D) To return a value from the method

Answer: A) To refer to the current instance of the class


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

x = [1, 2, 3]
x.append([4, 5])
print(x)
  • A) [1, 2, 3, 4, 5]
  • B) [1, 2, 3, [4, 5]]
  • C) [1, 2, 3, 4, 5, None]
  • D) [4, 5]

Answer: B) [1, 2, 3, [4, 5]]


15. What will the following code print?

for i in range(5):
    print(i, end=' ')
  • A) 0 1 2 3 4
  • B) 1 2 3 4 5
  • C) 0 1 2 3 4 5
  • D) 1 2 3 4

Answer: A) 0 1 2 3 4


16. Which of the following statements is used to catch exceptions in Python?

  • A) try
  • B) except
  • C) finally
  • D) All of the above

Answer: D) All of the above


17. What does the ‘pass’ statement do in Python?

  • A) Stops the execution
  • B) Skips the remaining code
  • C) Does nothing and acts as a placeholder
  • D) Exits the loop

Answer: C) Does nothing and acts as a placeholder


18. Which function is used to convert a string to an integer in Python?

  • A) intval()
  • B) str_to_int()
  • C) int()
  • D) convert()

Answer: C) int()


19. In Python, which of the following is an iterable?

  • A) List
  • B) Dictionary
  • C) String
  • D) All of the above

Answer: D) All of the above


20. What does the ‘continue’ statement do in a loop?

  • A) Exits the loop
  • B) Skips the current iteration and continues to the next
  • C) Stops the program
  • D) None of the above

Answer: B) Skips the current iteration and continues to the next


These questions should provide a solid foundation for anyone preparing for a Python interview. Good luck!