Python List Quiz: Python Programming Language MCQs

Python List Quiz. Python Language MCQs on Lists.

 

Python List Quiz

 

 

Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3])) ??

a) [x**-1 for x in [(1, 2, 3)]]
b) [1/x for x in [(1, 2, 3)]]
c) [1/x for x in (1, 2, 3)]
d) error

 

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

num = [‘One’, ‘Two’, ‘Three’]
for i, x in enumerate(num):
print(‘{}: {}’.format(i, x),end=” “)

a) 1: 2: 3:
b) Exception is thrown
c) One Two Three
d) 0: One 1: Two 2: Three

 

What will be the output of the following ??

print([if i%2==0: i; else: i+1; for i in range(4)])

a) [0, 2, 2, 4]
b) [1, 1, 3, 3]
c) error
d) none of the mentioned

 

What will be the output of the code ??

a=[“Apple”,”Ball”,”Cobra”]
<br class=”blank” />a.sort(key=len)
print(a)

a) [‘Apple’, ‘Ball’, ‘Cobra’]
b) [‘Ball’, ‘Apple’, ‘Cobra’]
c) [‘Cobra’, ‘Apple’, ‘Ball’]
d) Invalid syntax for sort()

 

Python List Quiz

 

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

print([[i+j for i in “abc”] for j in “def”])

a) [‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
b) [[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
c) [[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
d) [‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

 

What will be the output of the following Python ??

a = [1, 5, 7, 9, 9, 1]
<br class=”blank” />b=a[0]
<br class=”blank” />x= 0
for x in range(1, len(a)):
if a[x] > b:
b = a[x]
b= x
print(b)

a) 5
b) 3
c) 4
d) 0

 

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

print([i+j for i in “abc” for j in “def”])

a) [‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
b) [[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
c) [[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
d) [‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

 

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

def change(var, lst):
var = 1
lst[0] = 44
k = 3
a = [1, 2, 3]
change(k, a)
print(k)
print(a)

a) 3
[44, 2, 3]

b) 1
[1,2,3]

c) 3
[1,2,3]

d) 1
[44,2,3]

 

Python List Quiz

 

What will be the output of the following Python ??

print([i.lower() for i in “HELLO”])

a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) ‘hello’
c) [‘hello’]
d) hello

 

What will be the output of the following ??

a= [1, 2, 3, 4, 5]
for i in range(1, 5):
a[i-1] = a[i]
for i in range(0, 5):
print(a[i],end = ” “)

a) 5 5 1 2 3
b) 5 1 2 3 4
c) 2 3 4 5 1
d) 2 3 4 5 5

 

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

x = [i**+1 for i in range(3)]; print(x);

a) [0, 1, 2]
b) [1, 2, 5]
c) error, **+ is not a valid operator
d) error, ‘;’ is not allowed

 

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

a=165
b=sum(list(map(int,str(a))))
print(b)

a) 561
b) 5
c) 12
d) Syntax error

 

Python List Quiz

 

Which of the following is the correct expansion of list_1 = [expr(i) for i in list_0 if func(i)] ??

a) list_1 = []
for i in list_0:
if func(i):
list_1.append(i)

b) for i in list_0:
if func(i):
list_1.append(expr(i))

c) list_1 = []
for i in list_0:
if func(i):
list_1.append(expr(i))

d) none of the mentioned

 

What will be the output of the code ??

x=[[1],[2]]
print(” “.join(list(map(str,x))))

a) [1] [2]
b) [49] [50]
c) Syntax error
d) [[1]] [[2]]

 

What will be the output ??

my_string = “hello world”
k = [(i.upper(), len(i)) for i in my_string]
print(k)

a) [(‘HELLO’, 5), (‘WORLD’, 5)]
b) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
c) [(‘HELLO WORLD’, 11)]
d) none of the mentioned

Leave a Comment

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

error: Content is protected !!