Hello,
Does anyone know if Python has an in-built function to work to print out even values. Like range() for example.
Thanks
Hello,
Does anyone know if Python has an in-built function to work to print out even values. Like range() for example.
Thanks
I don't know if this is what you want to hear, but it's pretty trivial to filter out odd values with list comprehension.
evens = [x for x in range(100) if x%2 == 0]
or
evens = [x for x in range(100) if x&1 == 0]
You could also use the optional step size parameter for range
to count up by 2.