Python List
Python List is one of the most frequently used and very versatile datatype used in Python. In Python, lists are objects and it holds a number of other objects. Lists are very similar to arrays. It implements the sequence protocol, and also allows you to add and remove objects from the sequence. List literals are written within square brackets [ ] with the first element at index 0. There are many methods associated to them. Some of which are presented here below.
Python List MCQs
This section focuses on the "list" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1.Which of the following would give an error?
A. list1=[]
B. list1=[]*3
C. list1=[2,8,7]
D. None of the above
View Answer
Explanation: None of the above will result in error.
2.Which of the following is True regarding lists in Python?
A. Lists are immutable.
B. Size of the lists must be specified before its initialization
C. Elements of lists are stored in contagious memory location.
D. size(list1) command is used to find the size of lists.
View Answer
Explanation: Elements of lists are stored in contagious memory location is True regarding lists in Python.
3.What will be the output of below Python code?
print(list1[::-1])
A. [5,9,0,8]
B. [8,0,9]
C. [8,0,9,5]
D. [0,9,5]
View Answer
Explanation: [5,9,0,8] will be the output of below Python code.
4.Which of the following will give output as [23,2,9,75] ?
A. print(list1[1:7:2])
B. print(list1[0:7:2])
C. print(list1[1:8:2])
D. print(list1[0:8:2])
View Answer
Explanation: print(list1[1:8:2]) of the following will give output as [23,2,9,75].
5.The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student’s average mark be calculated?
A. print(avg(list1))
B. print(sum(list1)/len(list1))
C. print(sum(list1)/sizeof(list1))
D. print(total(list1)/len(list1))
View Answer
Explanation: the student’s average mark be calculated through print(sum(list1)/len(list1)).
6.What will be the output of following Python code?
print(min(list1))
A. c
B. C++
C. C
D. min function cannot be used on string elements
View Answer
Explanation: C will be the output of following Python code.
7.The elements of a list are arranged in descending order. Which of the following two will give same outputs?
i. print(list_name.sort())
ii. print(max(list_name))
iii. print(list_name.reverse())
iv. print(list_name[-1])
A. i, ii
B. i, iii
C. ii, iii
D. iii, iv
View Answer
Explanation: print(list_name.sort()) and print(list_name.reverse()) will give same outputs.
8. What will be the result after the execution of above Python code?
list1.pop(3)
print(list1)
A. [3,2,5,3,6]
B. [2,5,7,3,6]
C. [2,5,7,6]
D. [3,2,5,7,3,6]
View Answer
Explanation: [3,2,5,3,6] will be the result after the execution of above Python code.
9.What will be the output of below Python code?
list1.remove(2)
print(sum(list1))
A. 18
B. 19
C. 21
D. 22
View Answer
Explanation: 21 will be the result after the execution of above Python code.
10.What will be the output of below Python code?
list1.insert(5,8)
print(list1)
A. ["tom", "mary", "simon", 5]
B. ["tom", "mary", "simon", 8]
C. [8, "tom", "mary", "simon"]
D. Error
View Answer
Explanation: ["tom", "mary", "simon", 8] will be the result after the execution of above Python code.
Discussion
* You must be logged in to add comment.