x = 0.0
def is_zero(x):
return x is 0 or x is 0.0
print(f'is_zero: {x} : {is_zero(x)}')
print(f'express: {x} : {x is 0 or x is 0.0}')
Being two ways to use the same expression, I'd expect the same result. But when I run the code:
is_zero: 0.0 : False
express: 0.0 : True
Can anyone explain what is going on here? My ultimate aim here is to use the expression in a list comprehension to return a list with 0 and 0.0 removed (but not instances of False, hence using 'is' rather than '==' ). Unfortunately, the expression returns False when used in a list comprehension, just as it is when used in the return line above. And yet the expression clearly returns True so...?