In this tutorial, we will be focusing on methods of separating even and odd numbers using **Python programming language**. Python provides various ways to do this, including simple loops, list comprehension, and the use of built-in Python functions such as **filter()**.

### Step 1: Understanding the Basic Concept

An even number is any integer that can be divided by 2 with no remainder. Conversely, an odd number is an integer that cannot be divided by 2 evenly. In Python, the modulus operator **%** can be used to determine if a number is even or odd.

It gives the remainder of a division operation. So, if a number modulo 2 equals 0, it is an even number otherwise, it’s an odd number.

### Step 2: Using a Basic for Loop

The easiest way to separate odd and even numbers from a list is by using a basic **for loop**. You can iterate over the list and use the modulus operator to check each number.

1 2 3 4 5 6 7 8 9 |
def separate_numbers(numbers): even_numbers = [] odd_numbers = [] for num in numbers: if num % 2 == 0: even_numbers.append(num) else: odd_numbers.append(num) return even_numbers, odd_numbers |

### Step 3: Using List Comprehension

A more elegant and Pythonic way of separating odd and even numbers is by using **list comprehension**, which is a concise way to create lists.

1 2 3 4 |
def separate_numbers(numbers): even_numbers = [num for num in numbers if num % 2 == 0] odd_numbers = [num for num in numbers if num % 2 != 0] return even_numbers, odd_numbers |

### Step 4: Using Built-in Functions

Python has a powerful built-in function called **filter()** that takes in a function and a list and returns a new list made up of only those elements that meet a certain condition.

1 2 3 4 |
def separate_numbers(numbers): even_numbers = list(filter(lambda x: x % 2 == 0, numbers)) odd_numbers = list(filter(lambda x: x % 2 != 0, numbers)) return even_numbers, odd_numbers |

## Full Python Code

1 2 3 4 5 6 7 |
def separate_numbers(numbers): even_numbers = list(filter(lambda x: x % 2 == 0, numbers)) odd_numbers = list(filter(lambda x: x % 2 != 0, numbers)) return even_numbers, odd_numbers numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] print(separate_numbers(numbers)) |

## Output

([2, 4, 6, 8], [1, 3, 5, 7, 9])

## Conclusion

Separating odd and even numbers in Python is a fundamental task that can be accomplished using various methods, as we have seen. Whether you use a basic for loop, list comprehension, or the built-in filter() function, what matters is understanding the underlying principles.