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

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

    1. <legend id='sQCOY'><style id='sQCOY'><dir id='sQCOY'><q id='sQCOY'></q></dir></style></legend>
      • <bdo id='sQCOY'></bdo><ul id='sQCOY'></ul>
    2. <tfoot id='sQCOY'></tfoot>

    3. Python布尔比较和是

      Python boolean comparison and is(Python布尔比较和是)
      <i id='cvi8x'><tr id='cvi8x'><dt id='cvi8x'><q id='cvi8x'><span id='cvi8x'><b id='cvi8x'><form id='cvi8x'><ins id='cvi8x'></ins><ul id='cvi8x'></ul><sub id='cvi8x'></sub></form><legend id='cvi8x'></legend><bdo id='cvi8x'><pre id='cvi8x'><center id='cvi8x'></center></pre></bdo></b><th id='cvi8x'></th></span></q></dt></tr></i><div id='cvi8x'><tfoot id='cvi8x'></tfoot><dl id='cvi8x'><fieldset id='cvi8x'></fieldset></dl></div>

    4. <small id='cvi8x'></small><noframes id='cvi8x'>

              <bdo id='cvi8x'></bdo><ul id='cvi8x'></ul>
                  <tbody id='cvi8x'></tbody>
              • <legend id='cvi8x'><style id='cvi8x'><dir id='cvi8x'><q id='cvi8x'></q></dir></style></legend>
                <tfoot id='cvi8x'></tfoot>
                本文介绍了Python布尔比较和是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Python 3.6.2 控制台:

                Python 3.6.2 console:

                >>> 11 > 0 is True
                False
                

                但是

                >>> 0 is True
                False
                >>> 11 > False
                True
                

                那么,为什么 11 >0 是真?

                So, why 11 > 0 is True is False?

                推荐答案

                这是一个比较链接 因为 >is 都是比较运算符.

                This is an example of comparison chaining since both > and is are comparison operators.

                比较可以任意链接,例如,x <y <= z 是等价的到 x <y 和 y <= z,除了 y 只计算一次(但在这两个当 x x 时根本不计算 zy 被发现是假的).

                Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

                形式上,如果 a, b, c, ..., y, z 是表达式,而 op1, op2, ..., opN 是比较运算符,则 a op1 b op2 c ... y opN z 等价于a op1 b and b op2 c and ... y opN z,除了每个表达式是最多评估一次.

                Formally, if a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.

                因此,它等价于:

                >>> (11 > 0) and (0 is True)
                False
                

                这篇关于Python布尔比较和是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <tbody id='scYQh'></tbody>
                    • <small id='scYQh'></small><noframes id='scYQh'>

                      <legend id='scYQh'><style id='scYQh'><dir id='scYQh'><q id='scYQh'></q></dir></style></legend>

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

                        • <bdo id='scYQh'></bdo><ul id='scYQh'></ul>
                          <tfoot id='scYQh'></tfoot>