+ 3
== implicit data type conversion
So, in one of my code I compared a float and an int (say, 21.0 and 21) and 21.0 == 21 returned true. Now, I was expecting an error because of the difference in types but didn't get one. I have a therory: implicit data type conversion? Knew that arithmetic operators did this; was unaware it happened with == too. My question: is this a case of implicit data conversion or is there something else happening?
2 Answers
+ 8
There is a diffetence between == and is.
The expected behavior will occur on is
https://code.sololearn.com/cAktb4Zqr02J/?ref=app
+ 6
There is no implicit type conversion:
== compares value identity
is compares reference identity
21 references to integer and 21.0 references to double but the value of both is identical.
Maybe deep under the surface there is a conversion to allow == operator for comparing double and integer.