MCQ

Python MCQ and Answers – Lists

This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Lists”.
 

1. Which of the following declarartion will create a list?

A mylist = list()

B mylist = []

C mylist = list([0, 0, 0])

D All of the above

D
All of the above declarartions will create a list.
 

2. Which of the following declarartion can raise an error?

A mylist = []

B mylist = [] * 2

C mylist = [1, 2, 3]

D None of the mentioned

D
None of the mentioned will raise an error.
 

3. Which of the following statement is True concerning lists in Python?

A The size of the lists should be given before their initialization

B size(mylist) function is used to find the size of lists

C Items of lists are saved in a contagious memory location

D Lists are unchangeable.

C
Items of lists are saved in a contagious memory location is True concerning lists in Python.
 

4. What is the output when we execute the following code list("welcome")?

A [‘w’, ‘e’, ‘l’, ‘c’, ‘o’, ‘m’, ‘e’]

B [‘welcome’]

C [“w”, “e”, “l”, “c”, “o”, “m”, “e”]

D [“welcome”] 

A
The output is : [‘w’, ‘e’, ‘l’, ‘c’, ‘o’, ‘m’, ‘e’]
 

5. What is the output of the following code?
mylist = ["PHP", "Scala", "C", "C++", "Ada"]

print(min(mylist))

A C

B C++

C Scala

D Ada

D
min() function returns the minimum element(based on ASCII value) from the list.
 

6. What is the output of the following code?
mylist = [5,0,5,0,0,5]

mylist.pop(5)

print(mylist)

A [5, 0, 5, 0, 0, 5]

B [5, 0, 5, 0, 0]

C [0, 5, 0, 0, 5]

D [5, 0, 5, 0, 0, 5, 5] 

B
pop() function remove the last value from the list.
 

7. What is the output of the following code?
mylist = [1, 2, 3]

mylist.remove(1)

print(sum(mylist))

A 6

B 5

C 4

D 1

B
remove() function removes the first occurrence of the element with the given value.
 

8. What is the output of the following code?
mylist = ['h', 'e', 'l', 'l', 'o']

print(len(mylist))

A 4

B 5

C 6

D Compilation error

B
len() function returns the number of elements in a list.
 

9. What is the output of the following code?
mylist = ["A", "B", "C"]

mylist.insert(3,2)

print(mylist)

A [‘A’, ‘B’, 2, ‘C’]

B [‘A’, ‘B’, ‘C’, 2, 3]

C [‘A’, ‘B’, ‘C’, 3, 2]

D [‘A’, ‘B’, ‘C’, 2] 

D
mylist.insert(3,2) will insert “2” at the 3th position in mylist.
 

10. What is the output of the following code?
mylist = ["A", "B", "C", "D"]

print(mylist[-1])

A D

B C

C B

D A

A
mylist[-1] will return the last element.
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 *