Python整数除法产生浮点数 [英] Python integer division yields float

查看:324
本文介绍了Python整数除法产生浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 :更改分部运营商


//运算符可以明确地请求楼层划分。

The // operator will be available to request floor division unambiguously.

这篇关于Python整数除法产生浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆