MCQ

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

B
 

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

D
Max returns the maximum of the list.
 

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

C
Min returns the minimum of the list.
 

4. Suppose that list1 is [1, 2, 3], so what is the output of sum(list1)?

A 1

B 6

C 3

D Error

B
Sum returns the sum of all the elements in the list.
 

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

B
-1 corresponds to the last index of the list.
 

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']

B
 

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’]  
 

D
 

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)
D
 

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

C
print(i) is executed if the given character is not a vowel.
 

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

C
We iterate through the string, character by character.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *