# List MCQs Python: Python Programming MCQs

List MCQs Python. Python MCQs on Lists. 13 Multiple Choice Questions related to Lists in Python language.

## List MCQs Python

What will be the output ??

l=[“good”, “oh!”, “excellent!”, “#450”]
[n for n in l if n.isalpha() or n.isdigit()]

a) [‘good’, ‘oh’, ‘excellent’, ‘450’ ]
b) [‘good’]
c) [‘good’, ‘#450’]
d) [‘oh!’, ‘excellent!’, ‘#450’]

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

l1=[2,4,6]
l2=[-2,-4,-6]
for i in zip(l1, l2):
print(i)

a) 2, -2
4, -4
6, -6

b) [(2, -2), (4, -4), (6, -6)]

c) (2, -2)
(4, -4)
(6, -6)

d) [-4, -16, -36]

What will be the output of the following Python list comprehension ??

[j for i in range(2,8) for j in range(i*2, 50, i)]

a) A list of prime numbers up to 50
b) A list of numbers divisible by 2, up to 50
c) A list of non-prime numbers, up to 50
d) Error

List MCQs Python

What will be the output ??

s=[“pune”, “mumbai”, “delhi”]
[(w.upper(), len(w)) for w in s]

a) Error
b) [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]
c) [PUNE, 4, MUMBAI, 6, DELHI, 5]
d) [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]

What is the list comprehension equivalent for ??

{x : x is a whole number less than 20, x is even}

a) [x for x in range(1, 20) if (x%2==0)]
b) [x for x in range(0, 20) if (x//2==0)]
c) [x for x in range(1, 20) if (x//2==0)]
d) [x for x in range(0, 20) if (x%2==0)]

Write the list comprehension to pick out only negative integers from a given list ‘l’ ??

a) [x<0 in l]
b) [x for x<0 in l]
c) [x in l for x<0]
d) [x for x in l if x<0]

List MCQs Python

Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212] ??

a) [(2**x) for x in range(0, 13)]
b) [(x**2) for x in range(1, 13)]
c) [(2**x) for x in range(1, 13)]
d) [(x**2) for x in range(0, 13)]

What is the output of the following ??

l1=[1,2,3]
l2=[4,5,6]
[x*y for x in l1 for y in l2]

a) [4, 8, 12, 5, 10, 15, 6, 12, 18]
b) [4, 10, 18]
c) [4, 5, 6, 8, 10, 12, 12, 15, 18]
d) [18, 12, 6, 15, 10, 5, 12, 8, 4]

What is the list comprehension equivalent for: list(map(lambda x:x**-1, [1, 2, 3])) ??

a) [1|x for x in [1, 2, 3]]
b) [-1**x for x in [1, 2, 3]]
c) [x**-1 for x in [1, 2, 3]]
d) [x^-1 for x in range(4)]

List MCQs Python

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

l=[1,2,3,4,5]
[x&1 for x in l]

a) [1, 1, 1, 1, 1]
b) [1, 0, 1, 0, 1]
c) [1, 0, 0, 0, 0]
d) [0, 1, 0, 1, 0]

What will be the output of this code ??

A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
zip(A, B)

a) Address of the zip object
b) Address of the matrices A and B
c) No output
d) [3, 6, 9, 16, 20, 24, 35, 40, 45]

Write a list comprehension equivalent for the Python code below ??

for i in range(1, 101):
if int(i*0.5)==i*0.5:
print(i)

a) [i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
b) [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
c) [i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
d) [i for i in range(1, 100) if int(i*0.5)=(i*0.5)]

What will be the output of the following ??

A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
[[col1 * col2 for (col1, col2) in zip(row1, row2)] for (row1, row2) in zip(A, B)]

a) [0, 30, 60, 120, 160, 200, 300, 350, 400]
b) [[3, 6, 9], [16, 20, 24], [35, 40, 45]]
c) No output
d) Error

error: Content is protected !!