python traditional division, division, and real division Floor

1.python2.6 and before, x / y is a conventional division for integers fractional part will be omitted for the fractional part will remain floating.
2.python3 the x / y represents real division, regardless of any data type will remain fractional part.
In 3.python2 and 3, x // y can use, to python3, the // data type depends on the type of the result operand if the operand is a floating-point, floating-point result, otherwise integer . Another point addition, floor dividing the result is truncated to the next, the direct effect is rounded down.

#python3中
>>> 4 / 2
2.0
>>> 4.0 / 2
2.0
>>> 3 // 2
1
>>> 3.0 // 2
1.0
>>> -3//2
-2

Guess you like

Origin www.cnblogs.com/notfind/p/11343614.html