1==1.0 output True | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

1==1.0 output True

Why print(1==1.0) output True? The former is int and the latter is float

16th Feb 2019, 4:02 PM
zlyx525
2 Answers
+ 1
When you compare values of 2 data types, the interpreter will automatically turn them into 1 type. So the output will always be true. But on languages like java, js, (and maybe c langs) they use === , equality and type checking
16th Feb 2019, 4:06 PM
Seniru
Seniru - avatar
+ 1
On a deeper level, it depends on how the types, specifically their comparison tools, are designed. You can't just compare everything in Python, very often you'll get a TypeError when you try. But for int and float, one cross-class comparison is defined, I guess for convenience.
16th Feb 2019, 5:15 PM
HonFu
HonFu - avatar