Python Multiple Choice Quizs Question – Lists

Q 1. Suppose list1 is [1, 5, 9], what is sum(list1)?
A. 1
B. 15
C. 9
D. Error

Show Answer Answer:-B. 15
Explanation Sum returns the sum of all elements in the list.

Q 2. To shuffle the list(say list1) what function do we use?
A. list1.shuffle()
B. shuffle(list1)
C. random.shuffle(list1)
D. random.shuffleList(list1)

Show Answer Answer:-C. random.shuffle(list1)
Explanation Execute in the shell to verify.

Q 3. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
A. print(list1[2:])
B. print(list1[:2])
C. print(list1[:-2])
D. all of the mentioned

Show Answer Answer:-D. all of the mentioned
Explanation Slicing is allowed in lists just as in the case of strings.

Q 4. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
A. Error
B. None
C. 25
D. 2

Show Answer Answer:-C. 25
Explanation 1 corresponds to the last index in the list.

Q 5. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
A. [2, 33, 222, 14]
B. Error
C. 25
D. [25, 14, 222, 33, 2]

Show Answer Answer:-A. [2, 33, 222, 14]
Explanation Execute in the shell to verify.

Q 6. Suppose list1 is [2445,133,12454,123], what is max(list1)?
A. 2445
B. 133
C. 12454
D. 123

Show Answer Answer:-C. 12454
Explanation Max returns the maximum element in the list.

Q 7. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?
A. 3
B. 5
C. 25
D. 1

Show Answer Answer:-D. 1
Explanation Min returns the minimum element in the list.

Q 8. Which of the following commands will create a list?
A. list1 = list()
B. list1 = []
C. list1 = list([1, 2, 3])
D. all of the mentioned

Show Answer Answer:-D. all of the mentioned
Explanation Execute in the shell to verify

Q 9. What is the output when we execute list(“hello”)?
A. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
B. [‘hello’]
C. [‘llo’]
D. [‘olleh’]

Show Answer Answer:-A. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
Explanation Execute in the shell to verify.

Q 10. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
A. 7
B. 5
C. None
D. Error

Show Answer Answer:-B. 5
Explanation Execute in the shell and verify.

Posted

in

by

Comments

Leave a Reply

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

You cannot copy content of this page