• <tfoot id='zifvJ'></tfoot>
      <legend id='zifvJ'><style id='zifvJ'><dir id='zifvJ'><q id='zifvJ'></q></dir></style></legend>
    1. <small id='zifvJ'></small><noframes id='zifvJ'>

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

        • <bdo id='zifvJ'></bdo><ul id='zifvJ'></ul>

        Python中的“真"和“假"

        #39;True#39; and #39;False#39; in Python(Python中的“真和“假)

          <tfoot id='Thnzk'></tfoot>

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

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

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

                • 本文介绍了Python中的“真"和“假"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试运行这段代码:

                  path = '/bla/bla/bla'如果路径为真:打印真"别的:打印假"

                  它会打印 False.我认为 Python 将任何有价值的东西都视为 True.为什么会这样?

                  解决方案

                  来自 6.11.布尔运算:

                  <块引用><块引用>

                  在布尔运算的上下文中,以及当控制流语句使用表达式时,以下值被解释为假:假、无、所有类型的数字零以及空字符串和容器(包括字符串、元组、列表、字典、集合和冻结集合).所有其他值都被解释为 true.

                  我认为您误解的关键短语是解释为假"或解释为真".这并不意味着这些值中的任何一个都等于 True 或 False,甚至等于 True 或 False.

                  表达式 '/bla/bla/bla' 将在需要布尔表达式(如 if 语句中)的情况下被视为 true,但表达式 '/bla/bla/bla' 是 True 并且 '/bla/bla/bla' == True 将评估为 False 原因在 Ignacio 的回答中.

                  I tried running this piece of code:

                  path = '/bla/bla/bla'
                  
                  if path is True:
                      print "True"
                  else:
                      print "False"
                  

                  And it prints False. I thought Python treats anything with value as True. Why is this happening?

                  解决方案

                  From 6.11. Boolean operations:

                  In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.

                  The key phrasing here that I think you are misunderstanding is "interpreted as false" or "interpreted as true". This does not mean that any of those values are identical to True or False, or even equal to True or False.

                  The expression '/bla/bla/bla' will be treated as true where a Boolean expression is expected (like in an if statement), but the expressions '/bla/bla/bla' is True and '/bla/bla/bla' == True will evaluate to False for the reasons in Ignacio's answer.

                  这篇关于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不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  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替换为非空值)
                • <tfoot id='g9sNV'></tfoot>

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

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

                              <tbody id='g9sNV'></tbody>

                          • <legend id='g9sNV'><style id='g9sNV'><dir id='g9sNV'><q id='g9sNV'></q></dir></style></legend>