• <bdo id='SyHrf'></bdo><ul id='SyHrf'></ul>

  1. <legend id='SyHrf'><style id='SyHrf'><dir id='SyHrf'><q id='SyHrf'></q></dir></style></legend>
    1. <small id='SyHrf'></small><noframes id='SyHrf'>

      <tfoot id='SyHrf'></tfoot>

    2. <i id='SyHrf'><tr id='SyHrf'><dt id='SyHrf'><q id='SyHrf'><span id='SyHrf'><b id='SyHrf'><form id='SyHrf'><ins id='SyHrf'></ins><ul id='SyHrf'></ul><sub id='SyHrf'></sub></form><legend id='SyHrf'></legend><bdo id='SyHrf'><pre id='SyHrf'><center id='SyHrf'></center></pre></bdo></b><th id='SyHrf'></th></span></q></dt></tr></i><div id='SyHrf'><tfoot id='SyHrf'></tfoot><dl id='SyHrf'><fieldset id='SyHrf'></fieldset></dl></div>

    3. 负数楼层划分

      时间:2024-04-20

        <tbody id='hBP0x'></tbody>
          <tfoot id='hBP0x'></tfoot>
            <legend id='hBP0x'><style id='hBP0x'><dir id='hBP0x'><q id='hBP0x'></q></dir></style></legend>

            <small id='hBP0x'></small><noframes id='hBP0x'>

                <bdo id='hBP0x'></bdo><ul id='hBP0x'></ul>

                <i id='hBP0x'><tr id='hBP0x'><dt id='hBP0x'><q id='hBP0x'><span id='hBP0x'><b id='hBP0x'><form id='hBP0x'><ins id='hBP0x'></ins><ul id='hBP0x'></ul><sub id='hBP0x'></sub></form><legend id='hBP0x'></legend><bdo id='hBP0x'><pre id='hBP0x'><center id='hBP0x'></center></pre></bdo></b><th id='hBP0x'></th></span></q></dt></tr></i><div id='hBP0x'><tfoot id='hBP0x'></tfoot><dl id='hBP0x'><fieldset id='hBP0x'></fieldset></dl></div>
                本文介绍了负数楼层划分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                The expression 6 // 4 yields 1, where floor division produces the whole number after dividing a number.

                But with a negative number, why does -6 // 4 return -2?

                解决方案

                The // operator explicitly floors the result. Quoting the Binary arithmetic operations documentation:

                the result is that of mathematical division with the ‘floor’ function applied to the result.

                Flooring is not the same thing as rounding to 0; flooring always moves to the lower integer value. See the math.floor() function:

                Return the floor of x, the largest integer less than or equal to x.

                For -6 // 4, first the result of -6 / 4 is calculated, so -1.5. Flooring then moves to the lower integer value, so -2.

                If you want to round towards zero instead, you'll have to do so explicitly; you could do this with the int() function on true division:

                >>> int(-6 / 4)
                -1
                

                int() removes the decimal portion, so always rounds towards zero instead.

                这篇关于负数楼层划分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么在循环中使用睡眠时 Python 中的打印不会暂停? 下一篇:Python中的函数链

                相关文章

              • <legend id='sOr2K'><style id='sOr2K'><dir id='sOr2K'><q id='sOr2K'></q></dir></style></legend>

                    <bdo id='sOr2K'></bdo><ul id='sOr2K'></ul>

                1. <tfoot id='sOr2K'></tfoot>
                2. <small id='sOr2K'></small><noframes id='sOr2K'>

                  1. <i id='sOr2K'><tr id='sOr2K'><dt id='sOr2K'><q id='sOr2K'><span id='sOr2K'><b id='sOr2K'><form id='sOr2K'><ins id='sOr2K'></ins><ul id='sOr2K'></ul><sub id='sOr2K'></sub></form><legend id='sOr2K'></legend><bdo id='sOr2K'><pre id='sOr2K'><center id='sOr2K'></center></pre></bdo></b><th id='sOr2K'></th></span></q></dt></tr></i><div id='sOr2K'><tfoot id='sOr2K'></tfoot><dl id='sOr2K'><fieldset id='sOr2K'></fieldset></dl></div>