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

    1. <legend id='8IoiE'><style id='8IoiE'><dir id='8IoiE'><q id='8IoiE'></q></dir></style></legend>
        <bdo id='8IoiE'></bdo><ul id='8IoiE'></ul>

        <tfoot id='8IoiE'></tfoot>

      1. <small id='8IoiE'></small><noframes id='8IoiE'>

        为什么这不能作为数组成员测试?

        Why does this not work as an array membership test?(为什么这不能作为数组成员测试?)
            <tbody id='CGnas'></tbody>
        • <small id='CGnas'></small><noframes id='CGnas'>

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

              • <tfoot id='CGnas'></tfoot>
                1. <legend id='CGnas'><style id='CGnas'><dir id='CGnas'><q id='CGnas'></q></dir></style></legend>

                2. 本文介绍了为什么这不能作为数组成员测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  >>> 5 in [1, 2, 3, 4] == False
                  False
                  

                  I get that this is a bizarre way to test membership, and that

                  >>> 5 not in [1, 2, 3, 4]
                  True
                  

                  is the "correct" way. What confuses me is that its behavior is different from both

                  >>> (5 in [1, 2, 3, 4]) == False
                  True
                  

                  and

                  >>> 5 in ([1, 2, 3, 4] == False)
                  TypeError ...
                  

                  Have I missed something obvious? (Tested in Python 2.7 and Python 3.4).

                  To clarify, I understand the last three snippets. I am asking about the behavior of the first snippet, and why it is different.

                  解决方案

                  This is a chained comparison. You may have known that you can do

                  1 < 2 < 3
                  

                  in Python, and it's equivalent to (1 < 2) and (2 < 3). (Or maybe you didn't. Now you know.) Well, the same thing applies to in and ==.

                  5 in [1, 2, 3, 4] == False
                  

                  is equivalent to

                  (5 in [1, 2, 3, 4]) and ([1, 2, 3, 4] == False)
                  

                  Since [1, 2, 3, 4] is not equal to False, the whole expression evaluates to False.

                  这篇关于为什么这不能作为数组成员测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

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

                      • <tfoot id='xU6b9'></tfoot>

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

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