Write a list comprehension that builds a list of the even numbers from 1 to 10 (inclusive).
Answers
Answered by
0
The list comprehension for the given question is as follows:
[x for x in range(1, 11) if x%2==0]
- In python, list comprehension is an easy and compact syntax for creating a list from a string or another list.
- In this program, if statement is used in a list comprehension.
- The following program will produce an output in the form of a list in which all even numbers between 1 and 10 are printed.
Similar questions
English,
5 months ago
Math,
5 months ago
Hindi,
5 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago
Math,
1 year ago
Physics,
1 year ago