Search code examples
pythonnumpyscipyargumentsnumerical-methods

How do I add "args=(...)" into arguments of my own function?


in scipy there is a function 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. So the question is:

is there a way to add an argument args=(...) into arguments of my own function?


Solution

  • 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)