Search code examples
pythonfunctionpython-2.7parametersdefault

Is there any way to choose if a default parameter is used for a function?


For example:

def tune(a=2,b=3,c=4):
    return str(a) + " " + str(b) + " " + str(c) 

print tune(5, *default*, 7)

so that the output would be:

5 3 7

What do I put in place of the *default* to make this happen?


Solution

  • Use default named arguments. Explicitly mention that c has to take the value of 7

    >>> print tune(5, c= 7) 
    5 3 7