🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Comprehensions and Lambda: all 15 questions

Quiz: Comprehensions and Lambda · Question 14 of 15

What does this print? (code)

What does this print?

print([n * n for n in range(1, 6) if n % 2 == 1])
  1. A.[1, 4, 9, 16, 25]
  2. B.[4, 16]
  3. C.[1, 3, 5]
  4. D.[1, 9, 25]
Answer & explanation

Correct answer: [1, 9, 25]

Only odd n (1, 3, 5) pass the filter, and each is squared.

Can you get the rest right without peeking?

Take the timed Quiz: Comprehensions and Lambda quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →