0

Can somebody provide your reason for the below statement? 2==2.0 returns true. Why it is returning true?

2==2.0 returns true. Somebody describe how this could be true. type(2) returns int class type(2.0) returns float class V3.7 Python interpreter

23rd Jul 2019, 12:47 PM
Magesh Santhamani
Magesh Santhamani - avatar
1 ответ
+ 3
It checks the value. not the type; the statement checks if 2 equals 2, not if an int equals a float. EDIT: a further example, you could check if they are both the same type this way: if type(2.0) == type(2): print("True") else: print("False")
23rd Jul 2019, 12:52 PM
Rincewind
Rincewind - avatar