Python List Practice Questions: Python Programming MCQs

Python List Practice Questions. 15 Python MCQs related to Lists in Python Programming language.

 

Python List Practice Questions

 

 

What will be the output of the following ??

places = [‘Bangalore’, ‘Mumbai’, ‘Delhi’]
<br class=”blank” />places1 = places
places2 = places[:]
<br class=”blank” />places1[1]=”Pune”
places2[2]=”Hyderabad”
print(places)

a) [‘Bangalore’, ‘Pune’, ‘Hyderabad’]
b) [‘Bangalore’, ‘Pune’, ‘Delhi’]
c) [‘Bangalore’, ‘Mumbai’, ‘Delhi’]
d) [‘Bangalore’, ‘Mumbai’, ‘Hyderabad’]

 

What is the output of print(k) in the following Python code snippet ??

k = [print(i) for i in my_string if i not in “aeiou”]
print(k)

a) all characters of my_string that aren’t vowels
b) a list of Nones
c) list of Trues
d) list of Falses

 

What will be the output of the following ??

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

 

What will be the output ??

k = [print(i) for i in my_string if i not in “aeiou”]

a) prints all the vowels in my_string
b) prints all the consonants in my_string
c) prints all characters of my_string that aren’t vowels
d) prints only on executing print(k)

 

Python List Practice Questions

 

What will be the output of the following Python ??

word1=”Apple”
word2=”Apple”
list1=[1,2,3]
list2=[1,2,3]
print(word1 is word2)
print(list1 is list2)

a) True
True

b) False
True

c) False
False

d) True
False

 

What is the output of the following ??

l1=[1,2,3]
l2=[4,5,6]
l3=[7,8,9]
for x, y, z in zip(l1, l2, l3):
print(x, y, z)

 

a) 1 4 7
2 5 8
3 6 9

b) (1 4 7)
(2 5 8)
(3 6 9)

c) [(1, 4, 7), (2, 5, 8), (3, 6, 9)]

d) Error

 

What will be the output of the following code ??

lst=[[1,2],[3,4]]
print(sum(lst,[]))

a) [[3],[7]]
b) [1,2,3,4]
c) Error
d) [10]

 

What will be the output of this code ??

import math
[str(round(math.pi)) for i in range (1, 6)]

a) [‘3’, ‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
b) [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’, ‘3.141582’]
c) [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
d) [‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’]

 

Python List Practice Questions

 

What is the output of the following piece of code ??

a=list((45,)*4)
print((45)*4)
print(a)

a) 180
[(45),(45),(45),(45)]

b) (45,45,45,45)
[45,45,45,45]

c) 180
[45,45,45,45]

d) Syntax error

 

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

l=[[1 ,2, 3], [4, 5, 6], [7, 8, 9]]
[[row[i] for row in l] for i in range(3)]

 

a) Error

b) [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

c) 1 4 7
2 5 8
3 6 9

d) (1 4 7)
(2 5 8)
(3 6 9)

 

What will be the output of the following ??

a=[13,56,17]
a.append([87])
a.extend([45,67])
print(a)

a) [13, 56, 17, [87], 45, 67]
b) [13, 56, 17, 87, 45, 67]
c) [13, 56, 17, 87,[ 45, 67]]
d) [13, 56, 17, [87], [45, 67]]

 

Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9] ??

a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]

 

Python List Practice Questions

 

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

>>> a=[14,52,7]
>>>> b=a.copy()
>>> b is a

a) True

b) False

 

What will be the output of the following Python ??

l1=[10, 20, 30]
l2=[-10, -20, -30]
l3=[x+y for x, y in zip(l1, l2)]
l3

a) Error
b) 0
c) [-20, -60, -80]
d) [0, 0, 0]

 

What will be the output of the code ??

a=[1,2,3]
b=a.append(4)
print(a)
print(b)

a) [1,2,3,4]
[1,2,3,4]

b) [1, 2, 3, 4]
None

c) Syntax error

d) [1,2,3]
[1,2,3,4]

Leave a Comment

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

error: Content is protected !!