obtain the even numbers in a list using list comprehension
时间: 2024-06-03 19:09:51 浏览: 56
Obtain the hardware information of the PC Using C#.rar
Sure, you can obtain the even numbers in a list using list comprehension in Python! Here's an example code:
numbers_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_numbers_list = [number for number in numbers_list if number % 2 == 0]
print(even_numbers_list)
Output:
[2, 4, 6, 8, 10]
阅读全文