Python, why is 100 ** 0.5 == 4 + 6 true?

>>> 100**0.5 != 4+6
False
>>> 100**0.5 == 4+6
True
>>> 4+6
10
>>> 100**0.5
10.0
>>> 10.0==10
True

Who can tell me why 10.0==10there is True? I think 10.0 is this floatand 10 is int, I know that they are not equal in java.

+4
source share
4 answers

Quote from http://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex

Python fully supports mixed arithmetic: when a binary arithmetic operator has operands of different number types, the operand with the “narrower” type expands to the type of another, where a simple integer is narrower than a long integer, more complicated than a floating point.

So 10expanding to 10.0. That's why10 == 10.0

+7
source

Python float . float , , ( -). , Java - ( == Java). 10.0 == 10 , == () , int 10 10.0.

+3

u

>>> 10 == 10.0
True
>>> 10 is 10.0
False

- .

== - .

is . true, false .

+1

Python , .

>>> False == 0
True
>>> True == 1
True
>>> True == 0
False
>>> True == 22
False

.

0

All Articles