1. <small id='ieuTB'></small><noframes id='ieuTB'>

        <tfoot id='ieuTB'></tfoot>
        <legend id='ieuTB'><style id='ieuTB'><dir id='ieuTB'><q id='ieuTB'></q></dir></style></legend>

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

        Python - 作为条件的模运算

        Python - Modulo Operation as a Conditional(Python - 作为条件的模运算)

      1. <tfoot id='hdztA'></tfoot>
          <tbody id='hdztA'></tbody>
          <legend id='hdztA'><style id='hdztA'><dir id='hdztA'><q id='hdztA'></q></dir></style></legend>
          • <small id='hdztA'></small><noframes id='hdztA'>

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

                  <bdo id='hdztA'></bdo><ul id='hdztA'></ul>
                • 本文介绍了Python - 作为条件的模运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 lambda 函数测试素数中看到了模运算符的这种用法.如果据我所知这不是一个实际的布尔语句,有人可以解释为什么只要 i 大于 x 就会执行以下语句.如果分子大于分母,无论它们是否为因数,它也适用于除法.

                  I saw such a use of the modulo operator in a lambda function testing for primality. Can someone explain why the following statement will execute as long as i is greater than x if this isn't to my knowledge an actual boolean statement. It works with division as well if the numerator is greater than the denominator regardless if they are factors or not.

                  if x % i:
                      # Execute random foolishness
                  

                  注意:我只在 Python 和 Java 中尝试过,所以如果这适用于另一种语言,我深表歉意,因为它可能不是特定于语言的问题.

                  NOTE: I have only tried this in Python and Java so if this works in another language I apologize as it is probably not a language specific question.

                  推荐答案

                  Python 将非零值视为 True,因此 if x % i:if x % i 相同!= 0:.这只是测试 x 是否可以被 i 整除的快速方法.

                  Python treats non-zero values as True, so if x % i: is the same as if x % i != 0:. It's just a quick way to test if x is evenly divisible by i.

                  这篇关于Python - 作为条件的模运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                • <tfoot id='C5RLX'></tfoot>
                      <legend id='C5RLX'><style id='C5RLX'><dir id='C5RLX'><q id='C5RLX'></q></dir></style></legend>

                        <tbody id='C5RLX'></tbody>
                          <bdo id='C5RLX'></bdo><ul id='C5RLX'></ul>
                          <i id='C5RLX'><tr id='C5RLX'><dt id='C5RLX'><q id='C5RLX'><span id='C5RLX'><b id='C5RLX'><form id='C5RLX'><ins id='C5RLX'></ins><ul id='C5RLX'></ul><sub id='C5RLX'></sub></form><legend id='C5RLX'></legend><bdo id='C5RLX'><pre id='C5RLX'><center id='C5RLX'></center></pre></bdo></b><th id='C5RLX'></th></span></q></dt></tr></i><div id='C5RLX'><tfoot id='C5RLX'></tfoot><dl id='C5RLX'><fieldset id='C5RLX'></fieldset></dl></div>
                          • <small id='C5RLX'></small><noframes id='C5RLX'>