Python Practice › List Programs › Program 9

Squares of even numbers

EasyList Programs · 9 of 100

Write a Python program to print the squares of all even numbers in a list.

Advertisement
Input
[1, 2, 3, 4, 5, 6]
Output
[4, 16, 36]

Approach

  1. Filter even numbers and square them in one comprehension.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment