Python List Comprehension Syntax
Multiple Choice Medium
Question
What does `[x**2 for x in range(3)]` produce?
Hint
range(3) gives 0, 1, 2 — then square each.
Explanation
range(3) produces 0, 1, 2. The comprehension squares each: 02=0, 12=1, 2**2=4. The result is [0, 1, 4]. List comprehensions apply an expression to each item in an iterable.
Related Resources
Related Lessons
- List Comprehensions
Comprehension syntax.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.