11.5.2. 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.

The syntax for declaring variables with default values in Python is such that all positional arguments must come before any default arguments:

						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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset