Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default parameter value in function to value of another parameter [duplicate]

Is there a way to set a default parameter value in a function to be another one of the parameters?

I.e.

def (input1, input2 = input1)

I figure I can do something like what’s shown below, but want to know if there’s a better way

def (input1, input2 = 'blank')
      If input2 == 'blank':
           input2 = input1
like image 837
Jgreen727 Avatar asked Oct 29 '25 07:10

Jgreen727


1 Answers

You could try this. Maybe a little more clarification could help us help you more.

def do_stuff(input1, input2 = None):
    if input2 is None:
       input2 = input1

You were pretty close.

like image 187
Peter Jones Avatar answered Oct 31 '25 11:10

Peter Jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!