0

Why it’s printing True even I put a float value like with zero after decimal point - for example (7.0 , 5.0) ?

def is_int(x): if x == int(x): return True else: return False print(is_int(5.0)) print(type(5.0)) Please explain it! Thank You in advance.

2nd Sep 2021, 7:29 AM
Balraj Singh
1 Answer
+ 3
Because python evaluates 5.0 == 5 as true despite the difference in type. Try this instead: if type(x) == int:
2nd Sep 2021, 7:36 AM
Simon Sauter
Simon Sauter - avatar