为什么整数除法产生一个浮点数而不是另一个整数? [英] Why does integer division yield a float instead of another integer?
本文介绍了为什么整数除法产生一个浮点数而不是另一个整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/2
1.0
这是故意的吗?我强烈记得返回 int/int=int
的早期版本?我该怎么办,是否有新的除法运算符,还是必须始终强制转换?
Is this intended? I strongly remember earlier versions returning int/int=int
? What should I do, is there a new division operator or must I always cast?
推荐答案
看一看 PEP-238:更改除法运算符
Take a look at PEP-238: Changing the Division Operator
//操作员将可以明确地请求楼层划分.
The // operator will be available to request floor division unambiguously.
这篇关于为什么整数除法产生一个浮点数而不是另一个整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文