Python Mock Test

Instructions:

  • This mock test consists of 10 multiple-choice questions.
  • Choose the correct answer for each question.

1. What is the output of the following code?

print(type([1, 2, 3]))

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



2. Which keyword is used to define a function in Python?

a) func
b) function
c) def
d) define



3. What will be the output of this code?

x = 5
print(x == 5 and x < 10)

a) True
b) False
c) 5
d) Syntax Error



4. Which of the following is NOT a valid Python data type?

a) set
b) list
c) map
d) tuple



5. What is the correct way to open a file named "data.txt" for reading?

a) open("data.txt", "r")
b) open("data.txt", "read")
c) openfile("data.txt")
d) file.open("data.txt")



6. How do you insert COMMENTS in Python code?

a) // This is a comment
b) * This is a comment *
c) # This is a comment



7. What is the output of the following code?

print(2 ** 3)

a) 6
b) 8
c) 9
d) 5



8. Which of the following is used to create an empty set?

a) set()
b) {}
c) []
d) emptyset()



9. What does the len() function do?

a) Returns the length of an object
b) Adds two numbers
c) Finds a substring
d) Converts to integer



10. What is the correct way to write a for loop in Python?

a) for x to y:
b) foreach x in y:
c) for x in y:
d) for (x in y)