python里为啥int用的位置不同结果不同?-灵析社区

silennn

![](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241127/fb7c6ac9205d374a2b66c6b495ca9b04.png)!![](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241127/7bb149235285f22e3489d6cfeeede9c7.png)第一张图是在计算前把用int把input的字串符转变成整数计算结果和图二在计算过程中用int最后结果不同![](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241127/12d0573df670ef0ddb90af761e2c8d8f.png),但是用float的话结果就和图一一样了,求解答。

阅读量:22

点赞量:0

问AI
今天吃什么你说吧
在 python 里,3 / 4 = 0.75 。int(3) / int(4) = 0.75 。 但是 int(3 / 4) = 0 。 所以,cx = ax / a0 * 2 之后,int(cx) 跟 cx 可能不相等。但 float(cx) 和 cx 是相等的。