How can I check if a number is odd?



How can I check if a number is odd?


A number is odd if it is not evenly divisible by 2, which means we should make use of the modulo % operator. The modulo operator returns the remainder after devision, so if something is evenly divisible by 2, with a remainder of 0, it isn’t odd!
if my_number % 2 == 0: means a number is even.

FAQ: Learn Python - Practice Makes Perfect - purify

Hi all, Could u tell me why my funtion will be fail? and it can’t remove num 5 in list


.remove() is not the right approach to solve this problem, removing from the same list as you are looping over causes undesired behavior, like skipping successive odd/uneven numbers.


remove is the wrong approach because remove alters the length of the list and the index value of items further down the list of the item removed.