除法不同

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,爲浮點型。

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