除法不同

Python2 中除法默认向下取整,因此 1/2 = 0,为整型。

For (plain or long) integer division, the result is an integer. The result is always rounded towards minus infinity: 1/2 is 0, (-1)/2 is -1, 1/(-2) is -1, and (-1)/(-2) is 0.

而 Python3 中的除法为正常除法,会保留小数位,因此 1/2 = 0.5,为浮点型。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章