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

      <tfoot id='w5jEj'></tfoot>
        <bdo id='w5jEj'></bdo><ul id='w5jEj'></ul>

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

      1. 为什么'True == not False'是Python中的语法错误?

        时间:2023-09-01
        <legend id='ivuuY'><style id='ivuuY'><dir id='ivuuY'><q id='ivuuY'></q></dir></style></legend>

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

          <bdo id='ivuuY'></bdo><ul id='ivuuY'></ul>

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

              • <tfoot id='ivuuY'></tfoot>
                  <tbody id='ivuuY'></tbody>

                1. 本文介绍了为什么'True == not False'是Python中的语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Python 中使用 == 比较布尔值.但是当我应用布尔 not 运算符时,结果是语法错误:

                  Comparing boolean values with == works in Python. But when I apply the boolean not operator, the result is a syntax error:

                  Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) 
                  [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
                  Type "help", "copyright", "credits" or "license" for more information.
                  >>> True == True
                  True
                  >>> False == False
                  True
                  >>> True is not False
                  True
                  >>> True == not False
                    File "<stdin>", line 1
                      True == not False
                                ^
                  SyntaxError: invalid syntax
                  >>> 
                  

                  为什么这是一个语法错误?我希望 not False 是一个返回布尔值的表达式,并且 True == <x><x><的任何地方都是有效的语法/code> 是具有有效语法的表达式.

                  Why is this a syntax error? I would expect not False to be an expression that returns a boolean value, and True == <x> to be valid syntax wherever <x> is an expression with valid syntax.

                  推荐答案

                  和Python 中的运算符优先级(解释器认为您在比较 True 和 not,因为 == 的优先级高于 not).您需要一些括号来阐明操作顺序:

                  It has to do with operator precedence in Python (the interpreter thinks you're comparing True to not, since == has a higher precedence than not). You need some parentheses to clarify the order of operations:

                  True == (not False)
                  

                  一般情况下,您不能在没有括号的比较右侧使用 not.但是,我想不出你需要在比较右侧使用 not 的情况.

                  In general, you can't use not on the right side of a comparison without parentheses. However, I can't think of a situation in which you'd ever need to use a not on the right side of a comparison.

                  这篇关于为什么'True == not False'是Python中的语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <bdo id='3Lb8f'></bdo><ul id='3Lb8f'></ul>

                        <tfoot id='3Lb8f'></tfoot>

                        <small id='3Lb8f'></small><noframes id='3Lb8f'>

                          <tbody id='3Lb8f'></tbody>
                      1. <i id='3Lb8f'><tr id='3Lb8f'><dt id='3Lb8f'><q id='3Lb8f'><span id='3Lb8f'><b id='3Lb8f'><form id='3Lb8f'><ins id='3Lb8f'></ins><ul id='3Lb8f'></ul><sub id='3Lb8f'></sub></form><legend id='3Lb8f'></legend><bdo id='3Lb8f'><pre id='3Lb8f'><center id='3Lb8f'></center></pre></bdo></b><th id='3Lb8f'></th></span></q></dt></tr></i><div id='3Lb8f'><tfoot id='3Lb8f'></tfoot><dl id='3Lb8f'><fieldset id='3Lb8f'></fieldset></dl></div>
                        • <legend id='3Lb8f'><style id='3Lb8f'><dir id='3Lb8f'><q id='3Lb8f'></q></dir></style></legend>