Here are 10 more Python multiple-choice questions:
1. What will be the output of the following code?
x = {1, 2, 3, 4}
[Link](5)
print(x)
a) {1, 2, 3, 4}
b) {1, 2, 3, 4, 5}
c) [1, 2, 3, 4, 5]
d) Error
Answer: b) {1, 2, 3, 4, 5}
2. What is the correct way to create a tuple with a single element?
a) (1,)
b) (1)
c) [1]
d) tuple(1)
Answer: a) (1,)
3. What is the result of the following expression?
3 * "Python"
a) PythonPythonPython
b) Python * 3
c) Error
d) 3Python
Answer: a) PythonPythonPython
4. Which of the following is an immutable data type in Python?
a) list
b) set
c) tuple
d) dictionary
Answer: c) tuple
5. What does the len() function do in Python?
a) Counts the elements in a list or tuple
b) Measures the size of a file
c) Calculates the number of characters in a string
d) All of the above
Answer: d) All of the above
6. What is the output of the following code?
a = 10
b = 20
print(a == b)
a) True
b) False
c) Error
d) None
Answer: b) False
7. How do you create an infinite loop in Python?
a)
while True:
pass
b)
while 1:
pass
c) Both a and b
d) Python does not support infinite loops
Answer: c) Both a and b
8. Which of the following is not a valid Python function?
a) round()
b) max()
c) min()
d) sort()
Answer: d) sort()
(Explanation: sort() is a method of lists, not a standalone function.)
9. What will the following code print?
x = {1: 'a', 2: 'b'}
print(2 in x)
a) True
b) False
c) Error
d) None
Answer: a) True
10. What is the output of the following code?
a = 10
b=5
print(a // b)
a) 2.0
b) 2
c) 2.5
d) Error
Answer: b) 2
Let me know if you'd like more!