I would like to write a function in which the default value of one argument is a function of some arguments that are being passed to the same function. Something like this:
def function(x, y = function2(x)):
    ##definition of the function
Is it possible to write such a function in Python? I came across this answer for c++. But there is no method overloading in Python
Thanks in advance.
A pretty usual way of solving this is by using None as a placeholder:
def function(x, y=None):
    if y is None:
        y = f2(x)
    pass  # whatever function() needs to do
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With