List Comprehension
Multiple Choice Easy
Question
What does [x*2 for x in range(3)] produce?
Hint
List comprehensions create lists concisely.
Explanation
[x*2 for x in range(3)] iterates x = 0, 1, 2, computes x*2 for each, and creates [0, 2, 4]. List comprehensions are a concise way to create lists. They can include conditions: [x for x in range(10) if x % 2 == 0] gives even numbers. They are faster than equivalent for loops.
Related Resources
Related Lessons
- List Comprehensions
Learn list comprehensions.
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.