Default Values

Functions can have parameters with default values.

Example

Python
def sumWithDefaultValue(a, b = 10):
    return a + b;

sum1 = sumWithDefaultValue(5)
print(sum1)
sum2 = sumWithDefaultValue(5, 13)
print(sum2)

Output

15
18

Notes

Parameters with default values must always come last after any non-default parameters.

Example

Python
def defaultValuesMustBeAtTheEnd(a = 5, b):
    return a + b;

Output

def defaultValuesMustBeAtTheEnd(a = 5, b):
                               ^
SyntaxError: non-default argument follows default argument