PRACTICE

List Comprehensions

Lesson notes

Your task

Create a list of squares of 1 through 4 using a comprehension, then print it.

Expected output
[1, 4, 9, 16]
Loading…

OUTPUT

Worked solution
squares = [n * n for n in range(1, 5)]
print(squares)

Checks compare printed output, not your approach. Several solutions can be valid.

← Back to courses