Question
Which expression creates a list containing the squares of numbers from 0 through 4?
Select an option. Your answer will be checked instantly.
Correct Answer: D. `[x**2 for x in range(5)]`
Explanation:
A list comprehension evaluates `x**2` for each value produced by `range(5)`. The result is a new list containing 0, 1, 4, 9, and 16.
Leave a Reply