简体   繁体   English

如何在我自己的函数的参数中添加“ args =(…)”?

[英]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.

相关问题 如何使用可选参数和 *args arguments 调用 function? - How do I call a function with an optional and an *args arguments? 如何读取“args”中的 arguments 传递给 Python 中的内置 function [来源]? - How do I read the arguments in “args” passed to a builtin function in Python [source]? 如何将多个字符串 arguments 添加到我在 Python 中键入的 function? - How do I add multiple string arguments to my typing function in Python? 如何在python中返回函数参数args,kwargs - How can I return function arguments args, kwargs in python 如何在 Python 中定义自己的范围 function - How do I define my own range function in Python 在 co.Exec 节点中使用 python function 时,如何将我自己的类作为 arguments 传递? - How can I pass my own classes as arguments when using a python function in a co.Exec node? 调用函数时如何添加参数? - How do I add arguments when calling a function? 如何在 Python 的函数中清除位置 arguments? - How do I clear positional arguments in my function(s) in Python? 如何从** args返回函数的参数 - How to return a function's arguments from **args Python:为什么在函数中使用重载而不是 *args(尤其是当参数的类型不影响函数的运行方式时) - Python: why use overloading instead of *args in a function (especially when the type of arguments do not affect how the function runs)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM