• <bdo id='KbWdu'></bdo><ul id='KbWdu'></ul>
  • <small id='KbWdu'></small><noframes id='KbWdu'>

      <tfoot id='KbWdu'></tfoot>
        <legend id='KbWdu'><style id='KbWdu'><dir id='KbWdu'><q id='KbWdu'></q></dir></style></legend>

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

      1. Python逐元素元组操作,如sum

        时间:2023-09-01

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

        • <small id='o1mFa'></small><noframes id='o1mFa'>

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

                  <legend id='o1mFa'><style id='o1mFa'><dir id='o1mFa'><q id='o1mFa'></q></dir></style></legend>
                    <tbody id='o1mFa'></tbody>
                1. 本文介绍了Python逐元素元组操作,如sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法让 Python 中的元组操作像这样工作:

                  Is there anyway to get tuple operations in Python to work like this:

                  >>> a = (1,2,3)
                  >>> b = (3,2,1)
                  >>> a + b
                  (4,4,4)
                  

                  代替:

                  >>> a = (1,2,3)
                  >>> b = (3,2,1)
                  >>> a + b
                  (1,2,3,3,2,1)
                  

                  我知道它是这样工作的,因为 __add____mul__ 方法被定义为这样工作.那么唯一的方法就是重新定义它们?

                  I know it works like that because the __add__ and __mul__ methods are defined to work like that. So the only way would be to redefine them?

                  推荐答案

                  import operator
                  tuple(map(operator.add, a, b))
                  

                  这篇关于Python逐元素元组操作,如sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么 python 字符串和元组是不可变的? 下一篇:变换“元组列表";放入一个平面列表或矩阵

                  相关文章

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

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

                  1. <tfoot id='ATZw2'></tfoot>

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