Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python List Comprehension Review

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What will the following list comprehension output?

squares = [x**2 for x in range(5)]

print(squares)

a)

[0, 1, 4, 9, 16]

b)

[1, 4, 9, 16, 25]

c)

 [0, 2, 4, 6, 8]

d)

[1, 3, 5, 7, 9]

2.

What is the output of the following list comprehension?

vowels = ['a', 'e', 'i', 'o', 'u']
vowels2 = [vowel.upper() for vowel in vowels]

print(vowels2)

a)

['a', 'e', 'i', 'o', 'u']

b)

['A', 'E', 'I', 'O', 'U']

c)

['a', 'E', 'i', 'O', 'u']

d)

['A', 'e', 'I', 'o', 'U']

3.

What is the output of the following list comprehension?

list1 = ['H', 'E', 'L', 'L', 'O']
list2 = [list1.lower() for letters in list1]

print(list2)

a)

['H', 'E', 'L', 'L', 'O']

b)

['h', 'e', 'l', 'l', 'o']

c)

['h', 'E', 'l', 'L', 'o']

d)

['H', 'e', 'l', 'L', 'o']

4.

Which of the following is the output of the following code?

list1=[1,2,3,4,5]

list2 = [i + 5 for i in list1]

print(list2)

a)

[1, 2, 3, 4, 5]

b)

[6, 7, 8, 9, 10]

c)

[1, 2, 3, 4, 0]

d)

[0,0,0,0,1]

5.

What will the following list comprehension output?

list = [x * x for i in range(3)]

print(list)

a)

[0, 1, 2]

b)

[0, 1, 4]

c)

[0, 1, 4, 9]

d)

It throws an error

6.

What will the following list comprehension output?

list = [i * 10 for i in range(5)]

print(list)

a)

[0, 10, 20, 30, 40]

b)

[0, 5, 10, 15, 20]

c)

[0, 1, 2, 3, 4]

d)

[10, 10, 10, 10, 10]

7.

What will the following list comprehension output?

l = [i * 2 for i in range(1, 6)]

print(l)

a)

[0, 2, 4, 6, 8, 10]

b)

[2, 4, 6, 8, 10]

c)

[1, 2, 3, 4, 5]

8.

What will the following list comprehension output?

list = [x + 5 for x in range(5, 20, 5)]

print(list)

a)

[5, 10, 15, 20]

b)

[10, 15, 20]

c)

[5, 10, 15]

d)

[5, 10, 15, 20]

9.

What does this program print?

numbers = [x + x for x in range(4)]

print(numbers)

a)

[0, 1, 2, 3, 4]

b)

[0, 1, 2, 3]

c)

[2, 4, 6, 8]

d)

[0, 2, 4, 6]

10.

What does this program print?

numbers = [x % 2 == 0 for x in range(0, 6)]

print(numbers)

a)

[True, False, True, False, True, False]

b)

[0, 1, 0, 1, 0, 1, 0]

c)

[0, 1, 0, 1, 0, 1]

d)

[0, 1, 2, 3, 4, 5]