get odd numbers from list python code example
Example 1: get a list of even numbers in python
num_range = 10
even_numbers = [num for num in range(num_range) if num % 2 == 0]
# returns: [0, 2, 4, 6, 8]
# to include 10 in the output do
even_numbers = [num for num in range(num_range + 1) if num % 2 == 0]
Example 2: how to get odd numbers in python
# Here, rnge means range
rnge = int(input("Enter the range: "))
for i in range(1, rnge, 2):
print(i)