在 scipy 中有一个函数 quad()
:
quad(integrand, 0, 1, args=(a,b))
我有自己的函数来使用高斯legendgre求积分,当我将不同的函数与参数相结合时,我有点厌倦了添加它们。所以问题是:
有没有办法将参数 args=(...)
添加到我自己函数的参数中?
最佳答案
当然,
def my_function(value1, value2, value3, args=(0,0)):
print(value1, value2, value3, args)
# call with only 3 values
# it will use args=(0,0) as default
my_function(1,2,3)
# call with 3 values and args
my_function(4,5,6, args=(7,8))
输出:
1 2 3 (0, 0)
4 5 6 (7, 8)
关于python - 如何将 "args=(...)"添加到我自己函数的参数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50019969/