List Comprehension
Predict Output Easy
Question
What does this code print?
Code
result = [x**2 for x in range(4)]
print(result)
Hint
x**2 for x=0,1,2,3.
Explanation
range(4) gives 0,1,2,3. x**2: 0, 1, 4, 9. The list comprehension creates [0, 1, 4, 9].
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.