4 ms·
Why is 2/1 == 1.0 in Python3?
I was astonished by this result:
Python 3.8.5 (default, Aug 2 2020, 15:09:07)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/1
2.0
Why is that?
- rzzzwilson 6y agoOn my MacBook Pro, using python 3.8.5 I get >>> 2/1 2.0
- asplake 6y agoAlso (since Python 2.2): >>> 2//1 2
- gregjor 6y agoDocumented behavior: https://docs.python.org/3.3/reference/expressions.html#binary-arithmetic-operations https://docs.python.org/3.3/reference/expressions.html#binar... Dates to PEP 238 from 2001: https://www.python.org/dev/peps/pep-0238/ https://www.python.org/dev/peps/pep-0238/
- Someone 6y agoAre you sure about the “1.0” in the title? The descriptive text you wrote says you got “2.0”. 1.0 would surprise me, 2.0 is because, as others said, “/” was changed to do ‘normal’ division, with “//” a new operator for integer division (flooring the result)