• <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中的“真"和“假"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                • <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>