gpt4 book ai didi

python - 将函数输出作为参数传递给另一个函数

转载 作者:行者123 更新时间:2023-11-28 20:20:57 25 4
gpt4 key购买 nike

<分区>

我需要将 Python 中一个函数的输出作为参数传递给另一个函数。唯一的问题是第一个函数返回一个元组,整个元组需要传递给第二个函数。

例如:

我有一个库函数:

def some_function(some_string, some_number):
# does something
return (text,id)

现在我想将从 some_function 返回的 textid 作为参数传递给另一个函数。问题是该函数还有其他参数。我还需要检索将由 some_stringnumber 的不同值生成的许多文本和 ID。

根据满足的条件,我想调用另一个看起来像这样的函数

 if abcd:
other_function(name,phone,**some_function("abcd","123")**,age)
elif xyz:
other_function(name,phone,**some_function("xyz","911")**,age)
else:
other_function(name,phone,**some_function("aaaa","000")**,age)

那么我应该用什么替换 some_function("abcd","123") 以便它扩展元组并发送 textid 作为参数?

other_function 是这样定义的

def other_function(name, phone, text, id, age):
...
return

简单地将 some_function("aaaa","000") 作为参数传递是否有效?


我问这个是因为我写了一个简单的代码来检验我的假设,但它给了我一个空白输出。

def f(id,string):
return ("123", "hello")

def a(name, age, id, words, phone):
print name + age + id + words + phone


def main():
a("piyush", "23", f("12", "abc"), "123")

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com