(Nov-26-2020, 09:29 AM)perfringo Wrote: You have changed your original post but your claim was that in Python 3 floor division returns float and Python 2 floor division returns integer.
Quote:Better end this dream before it becomes a nightmare
--Rachel Cohn
Let's do reality check with Python 3:
>>> import sys >>> sys.version '3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23) \n[Clang 6.0 (clang-600.0.57)]' >>> 10 // 4 2With Python 2
>>> import sys >>> sys.version '2.7.16 (default, Oct 30 2020, 02:15:49) \n[GCC Apple LLVM 12.0.0 (clang-1200.0.30.4) [+internal-os, ptrauth-isa=sign+stri' >>> 10 // 4 2EDIT: if interested one can read PEP 238 Changing the Division Operator > Semantics of Floor Division:
Quote:Specifically, if a and b are of the same type, a//b will be of that type too. If the inputs are of different types, they are first coerced to a common type using the same rules used for all other arithmetic operators.
So if one of the operands is a float then indeed the floor division returns a float:
>>> 10.0 // 4 2.0 >>> 10 // 4.0 2.0
Yes, I had changed the question.
A book I'm referring showed 10//4.0 to evaluate to 2 in python2.6 and 2.0 in python3 in an example. However, I tried it in an online editor to find that 10//4.0 evaluated to 2.0 in python2.6 as well, the book must have made a typo.
So I changed the question from "why // changed" to "why // works the way it does"