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

前端 未结 7 1419
太阳男子
太阳男子 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:22

    == 
    

    is a comparison operator

    You are actually asking the interpreter if both sides of your expression are equal or not.

    In other words you are asking for it to return a Boolean value, not to convert data types. If you want to convert the data types you will have to do so implicitly in your code.

提交回复
热议问题