EVEN ODD NUMBER IN PYTHON PROGRAM

Publicado em: 23 Abril 2023
no canal de: jerry Python
30
3

In Python, an even list or an odd list is a list containing only even or odd integers respectively.

To create an even list or odd list in Python, you can use a list comprehension that filters out the odd or even integers from a given list using the modulo operator %.

Here's an example code for an even list:

pythonCopy code

Example of an even list numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] even_numbers = [num for num in numbers if num % 2 == 0] print(even_numbers) # Output: [2, 4, 6, 8, 10]

And here's an example code for an odd list:

pythonCopy code

Example of an odd list numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] odd_numbers = [num for num in numbers if num % 2 != 0] print(odd_numbers) # Output: [1, 3, 5, 7, 9]

In both cases, the list comprehension is used to iterate over each number in the numbers list, and the if statement filters out the even or odd integers using the modulo operator %.


Nesta página do site você pode assistir ao vídeo on-line EVEN ODD NUMBER IN PYTHON PROGRAM duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário jerry Python 23 Abril 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 30 vezes e gostou 3 espectadores. Boa visualização!