Tools, FAQ, Tutorials:
Parameter List in Function Definition Statements
How to specify parameters in the "def" statement to define a new function in Python?
✍: FYIcenter.com
When defining a function, you can specify the parameter list
as a comma separated list of variables with or without default values
in the following syntax:
def function_name(variable,variable,...,variable=default_value,...):
statement_block
Note that variables with default values must be specified after variables without default values.
When calling the function, you must provide values for all parameter variables except parameters with default values.
For example, the profile("Joe",25) expression calls the "profile()" function to be executed with 2 values provided to be assigned to its parameters.
>>> def profile(name,age=25):
... print("Name: "+name)
... print("Age: "+str(age))
...
>>> profile("Joe")
Name: Joe
Age: 25
Note that when assigning default value to a function parameter, you can use expressions with any variables available when the "def" statement is interpreted. For example, expression "legalAge+3" is used as the default "age" for the "profile" function:
>>> legalAge = 18
>>> def profile(name,age=legalAge+3):
... print("Name: "+name)
... print("Age: "+str(age))
...
>>> profile("Joe")
Name: Joe
Age: 21
⇒ Calling Function with Keyword Parameters
⇐ Function Calling Expressions
2022-10-26, ∼2061🔥, 0💬
Popular Posts:
How to use "json-to-xml" Azure API Policy Statement? The "json-to-xml" Policy Statement allows you t...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...
How to use the "send-one-way-request" Policy statement to call an extra web service for an Azure API...
How to Build my "sleep" Docker image from the Alpine image? I want the container to sleep for 10 hou...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...