Python Multiple Choice Questions – Lists

This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Lists”.

1. 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
View Answer

Answer: d
Explanation: Execute in the shell to verify

2. What is the output when we execute list(“hello”)?
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]
View Answer

Answer: a
Explanation: Execute in the shell to verify.

3. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
a) 5
b) 4
c) None
d) Error
View Answer

Answer: a
Explanation: Execute in the shell and verify.
advertisement
advertisement

4. Suppose list1 is [2445,133,12454,123], what is max(list1)?
a) 2445
b) 133
c) 12454
d) 123
View Answer

Answer: c
Explanation: Max returns the maximum element in the list.

5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?
a) 3
b) 5
c) 25
d) 1
View Answer

Answer: d
Explanation: Min returns the minimum element in the list.

6. Suppose list1 is [1, 5, 9], what is sum(list1)?
a) 1
b) 9
c) 15
d) Error
View Answer

Answer: c
Explanation: Sum returns the sum of all elements in the list.

7. 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)
View Answer

Answer: c
Explanation: Execute in the shell to verify.
advertisement

8. 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
View Answer

Answer: d
Explanation: Slicing is allowed in lists just as in the case of strings.

9. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error
b) None
c) 25
d) 2
View Answer

Answer: c
Explanation: -1 corresponds to the last index in the list.
advertisement

10. 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]
View Answer

Answer: a
Explanation: Execute in the shell to verify.

More MCQs on Python Lists:

Sanfoundry Global Education & Learning Series – Python.

To practice all areas of Python, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.