When does Python perform type conversion when comparing int and float?

前端 未结 7 1420
太阳男子
太阳男子 2021-01-12 23:22

Why does Python return True when I compare int and float objects which have the same value?

For example:

>&         


        
相关标签:
7条回答
  • 2021-01-13 00:23

    The == operator compares only the values but not the types. You can use the 'is' keyword to achieve the same effect as using === in other languages. For instance

    5 is 5.0
    

    returns False

    0 讨论(0)
提交回复
热议问题