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

    <legend id='muW43'><style id='muW43'><dir id='muW43'><q id='muW43'></q></dir></style></legend>

      1. “(1,) == 1,"是什么意思?在 Python 中?

        What#39;s the meaning of quot;(1,) == 1,quot; in Python?(“(1,) == 1,是什么意思?在 Python 中?)

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

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

                • <tfoot id='dmfo0'></tfoot>
                  本文介绍了“(1,) == 1,"是什么意思?在 Python 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在测试元组结构,发现使用 == 运算符时很奇怪:

                  I'm testing the tuple structure, and I found it's strange when I use the == operator like:

                  >>>  (1,) == 1,
                  Out: (False,)
                  

                  当我将这两个表达式赋值给一个变量时,结果为真:

                  When I assign these two expressions to a variable, the result is true:

                  >>> a = (1,)
                  >>> b = 1,
                  >>> a==b
                  Out: True
                  

                  这个问题不同于我的 Python tuple trailing comma syntax rule看法.我问 == 运算符之间的表达式组.

                  This questions is different from Python tuple trailing comma syntax rule in my view. I ask the group of expressions between == operator.

                  推荐答案

                  其他答案已经向您表明该行为是由于运算符优先级引起的,如文档 这里.

                  Other answers have already shown you that the behaviour is due to operator precedence, as documented here.

                  下次您遇到类似的问题时,我将向您展示如何自己找到答案.您可以使用 ast 解构表达式的解析方式模块:

                  I'm going to show you how to find the answer yourself next time you have a question similar to this. You can deconstruct how the expression parses using the ast module:

                  >>> import ast
                  >>> source_code = '(1,) == 1,'
                  >>> print(ast.dump(ast.parse(source_code), annotate_fields=False))
                  Module([Expr(Tuple([Compare(Tuple([Num(1)], Load()), [Eq()], [Num(1)])], Load()))])
                  

                  从这里我们可以看到代码被解析正如蒂姆·彼得斯解释的那样:

                  From this we can see that the code gets parsed as Tim Peters explained:

                  Module([Expr(
                      Tuple([
                          Compare(
                              Tuple([Num(1)], Load()), 
                              [Eq()], 
                              [Num(1)]
                          )
                      ], Load())
                  )])
                  

                  这篇关于“(1,) == 1,"是什么意思?在 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 与否?)

                  <small id='8r0rn'></small><noframes id='8r0rn'>

                    <legend id='8r0rn'><style id='8r0rn'><dir id='8r0rn'><q id='8r0rn'></q></dir></style></legend><tfoot id='8r0rn'></tfoot>
                      <tbody id='8r0rn'></tbody>
                      <bdo id='8r0rn'></bdo><ul id='8r0rn'></ul>

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