简体   繁体   English

返回由 function 调用的 2 个参数组合的新元组

[英]Return a new tuple with combination of 2 parameters called by an function

In Python , I have a list sayPython ,我有一个清单说

t = ("ab","de","fg","jk")

Make it so that the function above append I call returns a new tuple that is the combination of tup and value at the end of the new tuple.使我调用的 append 上方的append返回一个新元组,它是新元组末尾的tupvalue的组合。 I am getting a list at end but i need a tuple not an array.我最后得到一个列表,但我需要一个元组而不是数组。

Please anyone help me with this, as i new to PYTHON请任何人帮助我,因为我是 PYTHON 的新手

code part is:代码部分是:

t = ("ab","de","fg","jk")

def append(tup, value):
    return (tup+ value, value + tup)

append(*tuple)

After running above, i am getting append argument after * must be iterable not type在上面运行之后,我append argument after * must be iterable not type

You can concatenate tuples.您可以连接元组。 There is also a convention for expressing a one value tuple so the return could be as simple as: return tup + (value,)还有一个表示单值元组的约定,因此返回可以很简单: return tup + (value,)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM