Python
The problem of division in Python2
1 >>> 3/6 2 0 3 >>> 3.0/6 4 0.5 5 >>> 3.0/6.0 6 0.5< Span style= "COLOR: #008080" > 7 >>> 5/2 8 2 9 >>> 6.0/310 2.011 >>> 10.0/312 3.3333333333333335 >>> 0.2 +0.914 1.115 >>> 0.2 +0.1 16 0.30000000000000004
Because the computer to convert our input decimal into binary, floating-point number conversion binary, there will be a problem 0.1 to bits 0.000110011 conversion will not be exactly equal to the decimal 0.1, generally we will be rounding the results reserved two bits, for calculation.
Python2 is the division takes the integer part, thus obtains 3/6 =0,5/2=2
Can be referenced from the __FUTURE__ Import Division module to resolve
1 from __future__ Import Division 2 >>> 3/63 0.54 >>>
Remainder in Python
Two ways of the remainder
1,%
2, Divmod (), get quotient and remainder
1 >>> 6 52 13 >>> 6% 44 25 >>> divmod (6,4) /c5>6 (1, 2) quotient and remainder 7 >>> divmod (6,5)8 (1, 1)
Python Learning Note (iv) number (II)