Why does Python integer division yield a float instead of another integer? Why does Python integer division yield a float instead of another integer? python python

Why does Python integer division yield a float instead of another integer?


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

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


Oops, immediately found 2//2. This will output an int rather than a float.


Behavior of Division Operator in Python 2.7 and Python 3

In Python 2.7: By default, division operator will return integer output.

To get the result in double multiple 1.0 to "dividend or divisor"

100/35 => 2 #(Expected is 2.857142857142857)(100*1.0)/35 => 2.857142857142857100/(35*1.0) => 2.857142857142857

In Python 3

// => used for integer output/ => used for double output    100/35 => 2.857142857142857100//35 => 2100.//35 => 2.0    # floating-point result if divsor or dividend real


matomo