<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.

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

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  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替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                      <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>