<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 中?

        时间:2023-08-31

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

                  上一篇:元组对,使用 python 找到最小值 下一篇:python如何计算元组的哈希

                  相关文章

                  <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>
                    <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>