<legend id='4le4c'><style id='4le4c'><dir id='4le4c'><q id='4le4c'></q></dir></style></legend>

  • <small id='4le4c'></small><noframes id='4le4c'>

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

        <tfoot id='4le4c'></tfoot>

        如何检查 str(variable) 是否为空?

        How to check whether a str(variable) is empty or not?(如何检查 str(variable) 是否为空?)

              <tbody id='0jOgW'></tbody>

            <small id='0jOgW'></small><noframes id='0jOgW'>

            <tfoot id='0jOgW'></tfoot>
          1. <i id='0jOgW'><tr id='0jOgW'><dt id='0jOgW'><q id='0jOgW'><span id='0jOgW'><b id='0jOgW'><form id='0jOgW'><ins id='0jOgW'></ins><ul id='0jOgW'></ul><sub id='0jOgW'></sub></form><legend id='0jOgW'></legend><bdo id='0jOgW'><pre id='0jOgW'><center id='0jOgW'></center></pre></bdo></b><th id='0jOgW'></th></span></q></dt></tr></i><div id='0jOgW'><tfoot id='0jOgW'></tfoot><dl id='0jOgW'><fieldset id='0jOgW'></fieldset></dl></div>
            <legend id='0jOgW'><style id='0jOgW'><dir id='0jOgW'><q id='0jOgW'></q></dir></style></legend>
                  <bdo id='0jOgW'></bdo><ul id='0jOgW'></ul>
                  本文介绍了如何检查 str(variable) 是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何制作:

                  if str(variable) == [contains text]:
                  

                  条件?

                  (或者什么,因为我很确定我刚才写的完全错了)

                  (or something, because I am pretty sure that what I just wrote is completely wrong)

                  我正在尝试检查列表中的 random.choice["",](空白)还是包含 ["text",].

                  I am sort of trying to check if a random.choice from my list is ["",] (blank) or contains ["text",].

                  推荐答案

                  你可以只比较你的字符串和空字符串:

                  You could just compare your string to the empty string:

                  if variable != "":
                      etc.
                  

                  但你可以缩写如下:

                  if variable:
                      etc.
                  

                  说明:if 实际上是通过计算您给它的逻辑表达式的值来工作的:TrueFalse.如果您只是使用变量名(或hello"之类的文字字符串)而不是逻辑测试,则规则是:空字符串计为 False,所有其他字符串计为 True.空列表和数字 0 也算作假,而其他大多数情况都算作真.

                  Explanation: An if actually works by computing a value for the logical expression you give it: True or False. If you simply use a variable name (or a literal string like "hello") instead of a logical test, the rule is: An empty string counts as False, all other strings count as True. Empty lists and the number zero also count as false, and most other things count as true.

                  这篇关于如何检查 str(variable) 是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据帧进行分组)
                  <i id='YxleH'><tr id='YxleH'><dt id='YxleH'><q id='YxleH'><span id='YxleH'><b id='YxleH'><form id='YxleH'><ins id='YxleH'></ins><ul id='YxleH'></ul><sub id='YxleH'></sub></form><legend id='YxleH'></legend><bdo id='YxleH'><pre id='YxleH'><center id='YxleH'></center></pre></bdo></b><th id='YxleH'></th></span></q></dt></tr></i><div id='YxleH'><tfoot id='YxleH'></tfoot><dl id='YxleH'><fieldset id='YxleH'></fieldset></dl></div>

                    <tbody id='YxleH'></tbody>

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

                    <tfoot id='YxleH'></tfoot>

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