Python Practice › List Programs › Program 9
Squares of even numbers
Write a Python program to print the squares of all even numbers in a list.
Input
[1, 2, 3, 4, 5, 6]
Output
[4, 16, 36]
Approach
- Filter even numbers and square them in one comprehension.
Solution
numbers = [1, 2, 3, 4, 5, 6]print([n * n for n in numbers if n % 2 == 0])Output
[4, 16, 36]
Learn the concept
New to this topic? Read the lesson, then come back.