0% found this document useful (0 votes)
33 views6 pages

MCQ List

Uploaded by

divanshdutta880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

MCQ List

Uploaded by

divanshdutta880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LIST (MCQ)

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
2. What is the output when we execute list(“hello”)?
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’].
b) [‘hello’].
c) [‘llo’].
d) [‘olleh’]
3. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
a) 5
b) 4
c) None
d) Error
4. Suppose list1 is [2445,133,12454,123], what is max(list1) ?
a) 2445
b) 133
c) 12454
d) 123
5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?
a) 3
b) 5
c) 25
d) 1
6. Suppose list1 is [1, 5, 9], what is sum(list1) ?
a) 1
b) 9
c) 15
d) Error
7. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing
operation ?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned
8. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
a) Error
b) None
c) 25
d) 2
9. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ?
a) [2, 33, 222, 14].

Prepared by Namita Ranjan, KV AFS Bareilly Page 1


b) Error
c) 25
d) [25, 14, 222, 33, 2].
10. What is the output when following code is executed ?
names=[‘Amir’, ‘Bear’, ‘Charlton’, ‘Daman’]
print(names[-1][-1])
11. 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].
12. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is :
a) [0, 1, 2, 3].
b) [0, 1, 2, 3, 4].
c) [0.0, 0.5, 1.0, 1.5].
d) [0.0, 0.5, 1.0, 1.5, 2.0].
13. What is the output when following code is executed ?
List1=[11, 22, 33]
List2=[11, 22, 3]
print(List1<List2)
14. To insert 5 to the third position in list1, we use which command ?
a) list1.insert(3, 5)
b) list1.insert(2, 5)
c) list1.add(3, 5)
d) list1.append(3, 5)
15. To remove string “hello” from list1, we use which command ?
a) list1.remove(“hello”)
b) list1.remove(hello)
c) list1.removeAll(“hello”)
d) list1.removeOne(“hello”)
16. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?
a) 0
b) 1
c) 4
d) 2
17. 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].
18. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1) ?
a) [3, 4, 5, 20, 5, 25, 1, 3].
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].
Prepared by Namita Ranjan, KV AFS Bareilly Page 2
19. What is the output when the following code is executed ?
>>>”Welcome To Python”.split()
a) [“Welcome”, “to”, “Python”].
b) (“Welcome”, “to”, “Python”)
c) {“Welcome”, “to”, “Python”}
d) “Welcome”, “to”, “Python”
20. What is the output when the following code is executed ?
>>>list(”a#b#c#d”.split(‘#’))
a) [‘a’, ‘b’, ‘c’, ‘d’].
b) [‘a b c d’].
c) [‘a#b#c#d’].
d) [‘abcd’].
21. What is the output when following code is executed ?
myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i

print(indexOfMax)
a) 1
b) 2
c) 3
d) 4

22. What is the output when following code is executed?


myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
myList[i - 1] = myList[i]
for i in range(0, 6):
print(myList[i], end = " ")

a) 234561
b) 612345
c) 234566
d) 112345
23. What is the output when following code is executed ?
List1=[1,3]
List2=List1
List1[0]=4
Prepared by Namita Ranjan, KV AFS Bareilly Page 3
print(List2)
a) [1,3].
b) [4,3]
c) [1,4]
d) [1,3,4]
24. What will be the output?
names1 = [‘Amit’, ‘Bina’, ‘Charlie’]
if 'amit' in names1:
print(1)
else:
print(2)
a) None
b) 1
c) 2
d) Error
25. What will be the output of the following Python code?
names1 = ['Amir', 'Bala', 'Charlie']
names2 = [name.lower() for name in names1] #List comprehension
print(names2[2][0])
a) None

b) a

c) b

d) c

26. What will be the output of the following Python code?


numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print(len(numbers))

a) 4
b) 5
c) 8
d) 12
27. What will be the output of the following Python code?
list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
print(len(list1 + list2))

a) 2

Prepared by Namita Ranjan, KV AFS Bareilly Page 4


b) 4
c) 5
d) 8
28. What will be the output of the following Python code?
veggies = ['carrot', 'broccoli', 'potato', 'asparagus']
veggies.insert(veggies.index('broccoli'), 'celery')
print(veggies)
a) [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’]

b) [‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]

c) [‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]

d) [‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’]

29. 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

30. What will be the output of the following Python code?


values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]

for row in values:


row.sort()
for element in row:
print(element, end = " ")
print()
a) The program prints two rows 3 4 5 1 followed by 33 6 1 2
b) The program prints on row 3 4 5 1 33 6 1 2
c) The program prints two rows 3 4 5 1 followed by 33 6 1 2
d) The program prints two rows 1 3 4 5 followed by 1 2 6 33

Prepared by Namita Ranjan, KV AFS Bareilly Page 5


Prepared by Namita Ranjan, KV AFS Bareilly Page 6

You might also like