<legend id='Eb6Df'><style id='Eb6Df'><dir id='Eb6Df'><q id='Eb6Df'></q></dir></style></legend>
    • <bdo id='Eb6Df'></bdo><ul id='Eb6Df'></ul>

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

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

        <tfoot id='Eb6Df'></tfoot>

      1. Python中的多个“或"条件

        Multiple #39;or#39; condition in Python(Python中的多个“或条件)
        <legend id='jAKry'><style id='jAKry'><dir id='jAKry'><q id='jAKry'></q></dir></style></legend>
        <i id='jAKry'><tr id='jAKry'><dt id='jAKry'><q id='jAKry'><span id='jAKry'><b id='jAKry'><form id='jAKry'><ins id='jAKry'></ins><ul id='jAKry'></ul><sub id='jAKry'></sub></form><legend id='jAKry'></legend><bdo id='jAKry'><pre id='jAKry'><center id='jAKry'></center></pre></bdo></b><th id='jAKry'></th></span></q></dt></tr></i><div id='jAKry'><tfoot id='jAKry'></tfoot><dl id='jAKry'><fieldset id='jAKry'></fieldset></dl></div>
      2. <tfoot id='jAKry'></tfoot>

                <tbody id='jAKry'></tbody>

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

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

                  问题描述

                  我有一点代码问题,它适用于 IDLE 而不是 Eclipse,我可以这样写吗:

                  I have a little code issue and it works with IDLE and not with Eclipse, can I write this :

                  if  fields[9] != ('A' or 'D' or 'E' or 'N' or 'R'):
                  

                  而不是这个:

                  if  fields[9] != 'A' and fields[9] != 'D' and fields[9] != 'E' and fields[9] != 'N' and fields[9] != 'R':
                  

                  谢谢.

                  推荐答案

                  使用 not in 和一个序列:

                  if fields[9] not in ('A', 'D', 'E', 'N', 'R'):
                  

                  它针对一个元组进行测试,Python 将方便有效地将其存储为一个常量.您还可以使用集合文字:

                  which tests against a tuple, which Python will conveniently and efficiently store as one constant. You could also use a set literal:

                  if fields[9] not in {'A', 'D', 'E', 'N', 'R'}:
                  

                  但仅限于更新版本的 Python(Python 3.2 和更新版本) 会将其识别为不可变常量.对于较新的代码,这是最快的选择.

                  but only more recent versions of Python (Python 3.2 and newer) will recognise this as an immutable constant. This is the fastest option for newer code.

                  因为这是一个字符,你甚至可以使用一个字符串:

                  Because this is one character, you could even use a string:

                  if fields[9] not in 'ADENR':
                  

                  这篇关于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不丢失列)
                  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 数据帧进行分组)
                    • <legend id='SLCQG'><style id='SLCQG'><dir id='SLCQG'><q id='SLCQG'></q></dir></style></legend>
                      <i id='SLCQG'><tr id='SLCQG'><dt id='SLCQG'><q id='SLCQG'><span id='SLCQG'><b id='SLCQG'><form id='SLCQG'><ins id='SLCQG'></ins><ul id='SLCQG'></ul><sub id='SLCQG'></sub></form><legend id='SLCQG'></legend><bdo id='SLCQG'><pre id='SLCQG'><center id='SLCQG'></center></pre></bdo></b><th id='SLCQG'></th></span></q></dt></tr></i><div id='SLCQG'><tfoot id='SLCQG'></tfoot><dl id='SLCQG'><fieldset id='SLCQG'></fieldset></dl></div>

                      <tfoot id='SLCQG'></tfoot>

                        <bdo id='SLCQG'></bdo><ul id='SLCQG'></ul>
                        • <small id='SLCQG'></small><noframes id='SLCQG'>

                            <tbody id='SLCQG'></tbody>