[英]How do I add “args=(…)” into arguments of my own function?
in scipy there is a function quad()
: 在scipy中有一个函数
quad()
:
quad(integrand, 0, 1, args=(a,b))
I have my own function to take integrals using gauss legendgre quadrature, and when I integrate different functions with parameters im kinda tired of adding them. 我有自己的函数来使用高斯Legendgre正交求积分,当我将不同函数与参数集成在一起时,我有点累了。 So the question is:
所以问题是:
is there a way to add an argument args=(...)
into arguments of my own function? 有没有一种方法可以将参数
args=(...)
到我自己的函数的参数中?
sure, 当然,
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))
output: 输出:
1 2 3 (0, 0)
4 5 6 (7, 8)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.