Python MCQ and Answers – Part 11
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. Suppose that list1 is [‘h’, ‘e’, ‘l’, ‘l’, ‘o’], so what is the output of len(list1)
?
A 4
B 5
C Error
D None
2. Suppose that list1 is [100, 20, 5, 99], so what is the output of max(list1)
?
A 99
B 5
C 20
D 100
3. Suppose that list1 is [100, 15, 0, 2], so what is the output of min(list1)
?
A 100
B 15
C 0
D 2
4. Suppose that list1 is [1, 2, 3], so what is the output of sum(list1)
?
A 1
B 6
C 3
D Error
5. Suppose that list1 is [1, 28, 99, 15, 35], so what is the output of list1 [-1]
?
A 1
B 35
C None
D Error
6. Suppose a list with the name list1, contains 5 elements. You can get the 3rd item in the list using:
A list1[3]
B list1[2]
C list1['3']
D list1['2']
7. What is the output of the following code?
list1 = ['P', 'y', 't', 'h', 'o', 'n'] print(list1[:-3])
A [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
B [‘P’, ‘y’, ‘t’, ‘h’, ‘o’]
C [‘P’, ‘y’, ‘t’, ‘h’]
D [‘P’, ‘y’, ‘t’]
8. Suppose you need to display the constant PI defined in “math” module. Which of the following codes can perform this task?
A
print(pi)
B
print(math.pi)
C
from math import pi print(math.pi)
D
from math import pi print(pi)
9. What is the output of the following code?
v = [print(i) for i in str if i not in "aeiou"]
A Print all vowels in str
B Print all consonants in str
C Print all characters in str that are not vowels
D None of the above
10. What is the output of the following code?
str = "hello" l = [(i.upper(), len(i)) for i in str] print(l)
A [(‘HELLO’, 5)]
B [(‘hello’, 5)]
C [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)]
D None of the above