Default Arguments
Default arguments are parameters which are defined to have a default value if one is not provided in the function call for that argument. Such definitions are given in the function declaration header line. C++ and Java are other languages which support default arguments and whose declaration syntax is shared with Python: The argument name is followed by an “assignment of its default value. This assignment is merely a syntactical way of indicating that this assignment will occur if no value is passed in for that argument.
def function_name(posargs,defarg1=dval1, defarg2=dval2,…): "function_documentation_string" function_body_suite
Each default argument is followed by an assignment statement of its default value. If no value is given during a function call, then this assignment is realized.
Here is one example where a default argument comes in handy and has some usefulness in the growing electronic commerce industry:
>>> def taxMe(cost,rate = 10.05): return cost + (cost*rate) >>> taxMe(100) 1105.0 >>> taxMe(100,11) 1200