Home → Advanced → Comprehensions
Reading
0%

1 · List Comprehensions

A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses.

Python
squares = [x**2 for x in range(5)]
print(squares)  # [0, 1, 4, 9, 16]
🔁 Return Value

A list comprehension returns a new List object containing the results of the expression for each item.

📚 See Also