< BACKMake Note | BookmarkCONTINUE >
156135250194107072078175030179198180024228156016206217188240240204174055131039166095191176

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.


Last updated on 9/14/2001
Core Python Programming, © 2002 Prentice Hall PTR

< BACKMake Note | BookmarkCONTINUE >

© 2002, O'Reilly & Associates, Inc.