1. 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.
Ans : Elements of lists are stored in contagious memory location.
2. What will be the output of below Python code?
list1=[1,3,5,2,4,6,2]
list1.remove(2)
print(sum(list1))
A. 18
B. 19
C. 21
D. 22
Ans : 21
3. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
A. 5
B. 4
C. None
D. Error
Ans : 5
4. 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
Ans : all of the mentioned
5. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
A. Error
B. None
C. 25
D. 2
Ans : 25
6. What will be the result after the execution of above Python code?
list1=[3,2,5,7,3,6]
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]
Ans : [3,2,5,3,6]
7. Which of the following would give an error?
A. list1=[]
B. list1=[]*3
C. list1=[2,8,7]
D. None of the above
Ans : None of the above
8. Which of the following will give output as [23,2,9,75] ?
If list1=[6,23,3,2,0,9,8,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])
Ans : print(list1[1:8:2])
9. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?
A. 3
B. 5
C. 25
D. 1
Ans : 1
10. What is the output when we execute list(“hello”)?
A. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
B. [‘hello’]
C. [‘llo’]
D. [‘olleh’]
Ans : [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
11. 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]
Ans : [2, 33, 222, 14]
12. To add a new element to a list we use which command?
A. list1.add(5)
B. list1.append(5)
C. list1.addLast(5)
D. list1.addEnd(5)
Ans : list1.append(5)
13. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
a) 0
b) 1
c) 4
d) 2
Ans : 2
14. Suppose list1 is [1, 3, 2], What is list1 * 2?
A. [2, 6, 4]
B. [1, 3, 2, 1, 3]
C. [1, 3, 2, 1, 3, 2]
D. [1, 3, 2, 3, 2, 1]
Ans : [1, 3, 2, 1, 3, 2]
15. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?
A. [3, 4, 5, 20, 5, 25, 1]
B. [1, 3, 3, 4, 5, 5, 20, 25]
C. [3, 5, 20, 5, 25, 1, 3]
D. [1, 3, 4, 5, 20, 5, 25]
Ans : [3, 4, 5, 20, 5, 25, 1]
16. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?
A. [3, 4, 5, 20, 5, 25, 1, 3]
B. [1, 3, 3, 4, 5, 5, 20, 25]
C. [25, 20, 5, 5, 4, 3, 3, 1]
D. [3, 1, 25, 5, 20, 5, 4, 3]
Ans : [3, 4, 5, 20, 5, 25, 1, 3]
17. To which of the following the “in” operator can be used to check if an item is in it?
A. Lists
B. Dictionary
C. Set
D. All of the mentioned
Ans : All of the mentioned
18. How many elements are in m?
m = [[x, y] for x in range(0, 4) for y in range(0, 4)]
A. 8
B. 12
C. 16
D. 32
Ans : 16
19. What will be the output of the following Python code?
a=[[]]*3
a[1].append(7)
print(a)
A. Syntax error
B. [[7], [7], [7]]
C. [[7], [], []]
D. [[],7, [], []]
Ans : [[7], [7], [7]]
20. What will be the output of the following Python code?
def unpack(a,b,c,d):
print(a+d)
x = [1,2,3,4]
unpack(*x)
a) Error
b) [1,4]
c) [5]
d) 5
Ans : 5
0 Comments