- 3
Why 9>=9.0 is True ? 9==0 is also true? Boolean
Whereas 9 and 9.0 are equal
10 Antworten
+ 4
Zahed Shaikh If your question is about how the (==) and (>=) comparison operators, then review the original answer posted by visph.
Or perhaps your question is a bit more advanced than it would seem.
Perhaps, you're trying to understand how it's possible to use these comparison operators on equivalent numbers of different types: (integer and float).
If that's your actual question, then a simple explanation comes from the documentation:
https://docs.python.org/3/library/stdtypes.html#typesnumeric
"A comparison between numbers of different types behaves as though the exact values of those numbers were being compared."
Beyond that, the more advanced explanation may require a bit of understanding of various rules implemented by the Python runtime when resolving number types and using various Magic Methods.
I've put together some research notes and test code if you're interested.
https://code.sololearn.com/cQeKoPfzzYEd
+ 3
because >= means "greater than or equals"... and 9 equals 9.0 ^^
+ 3
Zahed Shaikh
See explanation here:
https://code.sololearn.com/coiPINkXA71Q/?ref=app
+ 2
9 == 9.0 is true, because 9 equals 9.0
+ 2
Zahed Shaikh It's really not clear what you're asking.
Are you asking, "Why not 9==9.0 are equal?"
Or are you asking, "Why not 9==9.0 is True?"
Or "Why not 9==9.0 is False?"
+ 1
Why not 9==9.0
+ 1
David Carroll , "Why 9==9.0 is true?"
&
, "Why 9>=9.0 is True?"
+ 1
Despite 9 is type of int and 9.0 type of float they are equal in number
0
Zahed Shaikh 9 (int) is converted into 9.0 (float) internally by Python. Thus, the two values are equal.
0
>= means greater than or EQUAL to. 9 equals 9.0 which is why its true