【问题标题】:How do I add "args=(...)" into arguments of my own function?如何将“args=(...)”添加到我自己函数的参数中?
【发布时间】:2018-04-25 10:30:26
【问题描述】:
在scipy中有一个函数quad():
quad(integrand, 0, 1, args=(a,b))
我有自己的函数来使用 gauss legendgre 求积积分,当我将不同的函数与参数集成时,我有点厌倦了添加它们。所以问题是:
有没有办法将参数args=(...) 添加到我自己函数的参数中?
【问题讨论】:
标签:
python
numpy
scipy
arguments
numerical-methods
【解决方案1】:
当然,
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)