Python integer division yields float


Question

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

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?

1
198
8/15/2009 9:51:52 PM

Accepted Answer

Take a look at PEP-238: Changing the Division Operator

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

257
8/15/2009 9:51:44 PM

Oops, immediately found 2//2.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon