Python List Interview Questions: Python Programming MCQs

Python List Interview Questions. Multiple Choice Questions on the topic of Lists in Python Language. 

 

Python List Interview Questions

 

 

What will be the output of the following ??

def m(list):
v = list[0]

for e in list:
if v < e: v = e
return v

values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for row in values:
print(m(row), end = ” “)

a) 3 33
b) 1 1
c) 5 6
d) 5 33

 

What is the output ??

a=”hello”
b=list((x.upper(),len(x)) for x in a)
print(b)

a) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)]
b) [(‘HELLO’, 5)]
c) [(‘H’, 5), (‘E’, 5), (‘L’, 5), (‘L’, 5), (‘O’, 5)]
d) Syntax error

 

What will be the output of the following ??

matrix = [[1, 2, 3, 4],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12, 13, 14, 15]]

for i in range(0, 4):
print(matrix[i][1], end = ” “)

a) 1 2 3 4
b) 4 5 6 7
c) 1 3 8 12
d) 2 5 9 13

 

What will be the output of the code ??

a=[1,2,3,4]
b=[sum(a[0:x+1]) for x in range(0,len(a))]
print(b)

a) 10
b) [1,3,5,7]
c) 4
d) [1,3,6,10]

 

What will be the output of this 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

 

Python List Interview Questions

 

What will be the output of the code ??

s=”a@b@c@d”
a=list(s.partition(“@”))
print(a)
b=list(s.split(“@”,3))
print(b)

a) [‘a’,’b’,’c’,’d’]
[‘a’,’b’,’c’,’d’]

b) [‘a’,’@’,’b’,’@’,’c’,’@’,’d’]
[‘a’,’b’,’c’,’d’]

c) [‘a’,’@’,’b@c@d’]
[‘a’,’b’,’c’,’d’]

d) [‘a’,’@’,’b@c@d’]
[‘a’,’@’,’b’,’@’,’c’,’@’,’d’]

 

What will be the output of the following Python ??

values = [[3, 4, 5, 1], [33, 6, 1, 2]]
v = values[0][0]
for lst in values:

for element in lst:
if v > element:
v = element
print(v)

a) 1
b) 3
c) 5
d) 6

 

What will be the output ??

import copy
a=[10,23,56,[78]]
b=copy.deepcopy(a)
a[3][0]=95
a[1]=34
print(b)

a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]

 

What will be the output of this Python code ??

values = [[3, 4, 5, 1], [33, 6, 1, 2]]
v = values[0][0]
for row in range(0, len(values)):
for column in range(0, len(values[row])):
if v < values[row][column]:
v = values[row][column]
print(v)

a) 3
b) 5
c) 6
d) 33

 

What will be the output of the following code ??

print(list(zip((1,2,3),(‘a’),(‘xxx’,’yyy’))))
print(list(zip((2,4),(‘b’,’c’),(‘yy’,’xx’))))

a) [(1,2,3),(‘a’),(‘xxx’,’yyy’)]
[(2,4),(‘b’,’c’),(‘yy’,’xx’)]

b) [(1, ‘a’, ‘xxx’),(2,’ ‘,’yyy’),(3,’ ‘,’ ‘)]
[(2, ‘b’, ‘yy’), (4, ‘c’, ‘xx’)]

c) Syntax error

d) [(1, ‘a’, ‘xxx’)]
[(2, ‘b’, ‘yy’), (4, ‘c’, ‘xx’)]

 

Python List Interview Questions

 

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

 

What will be the output of the following code ??

a=[10,23,56,[78]]
b=list(a)
a[3][0]=95
a[1]=34
print(b)

a) [10,34,56,[95]]
b) [10,23,56,[78]]
c) [10,23,56,[95]]
d) [10,34,56,[78]]

 

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

>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
c) [1, 2, 3, 4, 5, 6, 7, 8, 9]
d) [0, 1, 2, 1, 2, 3, 2, 3, 4]

Leave a Comment

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

error: Content is protected !!