Python Quiz 30 Questions Moderate Level
Python Quiz 30 Questions Moderate Level
Questions)
1. 1. What is the output of this code?
a = [1, 2, 3]
print(a[::-1])
A. [1, 2, 3]
B. [3, 2, 1]
C. [1, 3, 2]
D. Error
Answer: [3, 2, 1]
A. True
B. False
C. None
D. Error
Answer: False
4. 4. How many times will print() be executed?
for i in range(2, 10, 2):
print(i)
A. 4
B. 5
C. 6
D. 3
Answer: 4
A. Even
B. Odd
C. 10
D. True
Answer: Even
A. 3
B. 5
C. 8
D. Error
Answer: 8
7. 7. Which of the following will NOT raise an error?
A. 10
B. Error
C. None
D. Undefined
Answer: 10
A. 6
B. 3
C. Error
D. 1
Answer: 6
10. 10. Which of the following is true about default parameters?
A. nohtyP
B. Python
C. Error
D. nothyP
Answer: nohtyP
A. {1, 2, 2, 3}
B. {1, 2, 3}
C. [1, 2, 3]
D. Error
Answer: {1, 2, 3}
A. sorted()
B. sort()
C. reversed()
D. max()
Answer: sort()
A. a becomes (10, 2, 3)
B. Error
C. None
D. Tuple is updated
Answer: Error
17. 17. Which of these will handle both IndexError and ValueError?
A. try:
# code
except (IndexError, ValueError): pass
B. try:
# code
except IndexError and ValueError: pass
C. try:
# code
except: IndexError, ValueError
D. try:
# code
catch IndexError, ValueError:
Answer: try:
# code
except (IndexError, ValueError): pass
A. <class 'file'>
B. <class 'str'>
C. <class '_io.TextIOWrapper'>
D. <class 'TextFile'>
A. open("f.txt", "r")
B. open("f.txt", "w")
C. file.open("f.txt")
D. write("f.txt")
C. Always runs
A. Initializes an object
B. Deletes an object
A. A
B. name
C. self.name
D. Error
Answer: A
B. Refers to module
D. A placeholder
D. None
B. [0, 1, 4]
C. [0, 1, 2]
D. Error
Answer: [0, 1, 4]
A. [(1,3), (2,4)]
B. [1,2,3,4]
C. [[1,3], [2,4]]
D. None
A. [1,2,3]
B. <map object>
C. 1,2,3
D. Error
A. No value
B. None
C. Error
D. 0
Answer: No value
30. 30. Which of the following is the correct syntax for a lambda function?
A. lambda x: x+1
C. lambda = x: x+1