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

        <bdo id='8yvy6'></bdo><ul id='8yvy6'></ul>

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

      1. <tfoot id='8yvy6'></tfoot>

        Python 不能在函数中定义元组

        Python can#39;t define tuples in a function(Python 不能在函数中定义元组)

        • <tfoot id='HLs0D'></tfoot>
          • <small id='HLs0D'></small><noframes id='HLs0D'>

            <legend id='HLs0D'><style id='HLs0D'><dir id='HLs0D'><q id='HLs0D'></q></dir></style></legend>
              <tbody id='HLs0D'></tbody>

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

                  本文介绍了Python 不能在函数中定义元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  由于某种原因,在 python 中,每次我尝试在函数中定义元组时都会出现语法错误.例如我有一个向程序添加向量的函数,它看起来像这样:

                  For some reason in python everytime I try to define tuples in a function I get a syntax error. For example I have a function that adds vectors to the program, it looks like this:

                  def add_vectors((angle_1, l_1),(angle_2, l_2)):
                      x=math.sin(angle1)*l_1+math.sin(angle2)*l_2
                      y=math.cos(angle1)*l_1+math.cos(angle2)*l_2
                  
                      angle=0.5*math.pi-math.atan2(y, x)
                      length=math.hypot(x, y)
                      return (angle, length)
                  

                  这似乎没问题,但解释器说存在语法错误并突出显示第一个元组的第一个括号.我正在使用 Python 3.2.3.我做错了什么?

                  Which seems alright, but the interpretor says there is a syntax error and highlights the first bracket of the first tuple. I am using Python 3.2.3. What am I doing wrong?

                  推荐答案

                  Python3 不再支持元组参数:http://www.python.org/dev/peps/pep-3113/

                  Tuple parameters are no longer supported in Python3: http://www.python.org/dev/peps/pep-3113/

                  您可以在函数的开头解包您的元组:

                  You may unpack your tuple at the beginning of your function:

                  def add_vectors(v1, v2):
                      angle_1, l_1 = v1
                      angle_2, l_2 = v2
                      x=math.sin(angle1)*l_1+math.sin(angle2)*l_2
                      y=math.cos(angle1)*l_1+math.cos(angle2)*l_2
                  
                      angle=0.5*math.pi-math.atan2(y, x)
                      length=math.hypot(x, y)
                      return (angle, length)
                  

                  这篇关于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 与否?)
                1. <legend id='JGdvK'><style id='JGdvK'><dir id='JGdvK'><q id='JGdvK'></q></dir></style></legend>
                    <bdo id='JGdvK'></bdo><ul id='JGdvK'></ul>
                    <i id='JGdvK'><tr id='JGdvK'><dt id='JGdvK'><q id='JGdvK'><span id='JGdvK'><b id='JGdvK'><form id='JGdvK'><ins id='JGdvK'></ins><ul id='JGdvK'></ul><sub id='JGdvK'></sub></form><legend id='JGdvK'></legend><bdo id='JGdvK'><pre id='JGdvK'><center id='JGdvK'></center></pre></bdo></b><th id='JGdvK'></th></span></q></dt></tr></i><div id='JGdvK'><tfoot id='JGdvK'></tfoot><dl id='JGdvK'><fieldset id='JGdvK'></fieldset></dl></div>

                    1. <small id='JGdvK'></small><noframes id='JGdvK'>

                          <tbody id='JGdvK'></tbody>
                          1. <tfoot id='JGdvK'></tfoot>