gpt4 book ai didi

javascript - Python有没有办法通过函数传递参数

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

Javascript 在每个函数中都有一个构造不佳但方便的“arguments”变量,因此您可以像这样通过函数传递参数:

function foo(a, b, c) {
return bar.apply(this, arguments);
}
function bar(a, b, c) {
return [a, b, c];
}
foo(2, 3, 5); // returns [2, 3, 5]

有没有一种简单的方法可以在 Python 中做类似的事情?

最佳答案

>>> def foo(*args):
... return args

>>> foo(1,2,3)
(1,2,3)

这是你想要的吗?

关于javascript - Python有没有办法通过函数传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9917541/

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