- 3

Why 9>=9.0 is True ? 9==0 is also true? Boolean

Whereas 9 and 9.0 are equal

29th Jun 2021, 10:45 PM
Zahed Shaikh
Zahed Shaikh - avatar
10 Réponses
+ 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
30th Jun 2021, 8:04 AM
David Carroll
David Carroll - avatar
+ 3
because >= means "greater than or equals"... and 9 equals 9.0 ^^
29th Jun 2021, 11:03 PM
visph
visph - avatar
30th Jun 2021, 1:26 AM
A͢J
A͢J - avatar
+ 2
9 == 9.0 is true, because 9 equals 9.0
29th Jun 2021, 11:07 PM
visph
visph - avatar
+ 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?"
30th Jun 2021, 12:30 AM
David Carroll
David Carroll - avatar
+ 1
Why not 9==9.0
29th Jun 2021, 11:06 PM
Zahed Shaikh
Zahed Shaikh - avatar
+ 1
David Carroll , "Why 9==9.0 is true?" & , "Why 9>=9.0 is True?"
30th Jun 2021, 3:06 AM
Zahed Shaikh
Zahed Shaikh - avatar
+ 1
Despite 9 is type of int and 9.0 type of float they are equal in number
30th Jun 2021, 5:52 AM
Shadoff
Shadoff - avatar
0
Zahed Shaikh 9 (int) is converted into 9.0 (float) internally by Python. Thus, the two values are equal.
1st Jul 2021, 2:32 AM
Calvin Thomas
Calvin Thomas - avatar
0
>= means greater than or EQUAL to. 9 equals 9.0 which is why its true
1st Jul 2021, 8:36 AM
Arseni
Arseni - avatar