LearnFrenzy
Sign in Take a free test

List Comprehensions · Exercise 1 of 4

List Comprehensions List Comprehensions MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on Python comprehensions: filters, if-else, several for clauses, nesting, dict and set comprehensions, generator expressions and scope. Pick an option to check your answer instantly.

Question 11 Hard

What does [n for n in range(20) if n % 2 if n % 3] keep?

A Numbers that are odd AND not divisible by 3
B Numbers that are odd OR not divisible by 3
C Only multiples of 6
D It is a SyntaxError
Question page & discussion
Question 12 Medium

What does result = [print(x) for x in range(3)] leave in result?

A [0, 1, 2]
B [None, None, None]
C None
D An empty list
Question page & discussion
Question 13 Medium

What does len(x for x in range(5)) do?

A Returns 5
B Returns 0
C Raises TypeError – generators have no length
D Returns None
Question page & discussion
Question 14 Medium

Which expression creates a 3 × 3 grid whose rows are independent lists?

A [[0] * 3] * 3
B [0] * 9
C [[0] * 3 for _ in range(3)]
D [[0, 0, 0]] * 3
Question page & discussion
Question 15 Easy

What is the length of {w.lower() for w in ["Hi", "hi", "HI", "hey"]}?

A 4
B 3
C 1
D 2
Question page & discussion
Up next · Exercise 2Predict the Output15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links