PRACTICE / UNDERSTAND / REPEAT

Python: Comprehensions

Practice comprehensions with self-contained questions. Check your answer, then use the explanation to understand the reasoning.

20 questionsAnswers explainedFree · no login
Question 1 of 20
Comprehensions · MCQQuestion link ↗

What is the sum of the squared values?

print(sum(x * x for x in [1, 2]))
Choose one answer
Answer & explanation

Answer: 5

The comprehension squares each input and sum adds the results.