擅长:python、mysql、java
<p>这与舍入规则有关。举个简单的例子:</p>
<pre><code>>>> -3/(-2)
1
>>> -3/2*-1
2
</code></pre>
<p><code>1.5</code>向下四舍五入到<code>1</code>,<code>-1.5</code>向下四舍五入到<code>-2</code>。在某种程度上是一致的。你知道吗</p>
<p><a href="https://docs.python.org/2/reference/expressions.html#binary-arithmetic-operations" rel="nofollow">Doc reference:</a></p>
<blockquote>
<p>Plain or long integer division yields an integer of the same type; the
result is that of mathematical division with the ‘floor’ function
applied to the result.</p>
</blockquote>
<p>如果希望在Python2.x中得到浮点结果,则需要显式转换(或仅使用浮点文本),或者执行<code>from __future__ import division</code>。在python3.x中,除法总是产生一个浮点(<a href="https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations" rel="nofollow">ref</a>)。你知道吗</p>