0

Following is my function :

def compare(a, b, key=None,*arg2):
    print(a,b,key)

So in this how do we call the function without specifying value for the key, but providing value for the arg2 tuple...

Thanks.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
Narasimhan
  • 11
  • 5

1 Answers1

0

If I am not wrong You want to pass default value of variable key. If so you can change the order of the variables. like this

def compare(a, b,*arg2,key=None):
    print(a,b,key,arg2)

compare(2,3,12,134,135,35,4567647,67865)
#output: 2 3 None (12, 134, 135, 35, 4567647, 67865)
Nandish Patel
  • 116
  • 13
  • Thanks! This seems to work in case I do not want to send the key value... but what if i want to pass the value? I mean, in some cases i do not want to pass, and in some use cases i would want to pass the 'key' value explicitly. – Narasimhan Jun 08 '17 at 12:06
  • so you don't want to pass default value, then i am afraid i don't have any way to do that man.sorry:( – Nandish Patel Jun 10 '17 at 15:55