gpt4 book ai didi

python - 为什么 -ve int 的除法值与 +ve one 不同?

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:22 27 4
gpt4 key购买 nike

我试过了 Python .我知道使用整数并进行除法只会返回商的整数值,截断小数部分。关于这一点:

3 / 2 = 1

听起来完全没问题......但是当股息为负时,我很难理解幕后发生的事情??

-3 / 2 = -2

这是输出:

enter image description here

最佳答案

那里的整数除法只是取最后得到的数的底数。

3/2  -> floor(1.5)  ->  1
-3/2 -> floor(-1.5) -> -2

关于python - 为什么 -ve int 的除法值与 +ve one 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19890035/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com