
Compare int and float in Python - 3 and 3.0 are same
In Python, 3 is int and 3.0 is float. Both types are different but both has the same value, that is 3 == 3.0 is true.
if 3 == 3.0:
print('3 is 3.0.')
else:
print('3 is not 3.0.')
# 3 is 3.0.
And 3 < 3.0 is false.
if 3 < 3.0:
print('3 < 3.0')
else:
print('3 >= 3.0')
# 3 >= 3.0
The Python comparison operator ==
checks values and returns true even if those types are different.
a = 1 == 1.0
b = 1 == 1.00
print(a) # True
print(b) # True
Comments
Powered by Markdown