Tools, FAQ, Tutorials:
Calling Function with Keyword Parameters
How to call a function with keyword parameters instead of positional parameters?
✍: FYIcenter.com
By default, you should call a function with a list of data objects as positional parameters
matching the parameter list in the function "def" statement.
But you can also call a function with name value pairs as keyword parameters listed after any positional parameters.
The Python example below shows you how to use keyword parameters to call a function:
>>> def profile(name,age=25,role="guest"):
... print("Name: "+name)
... print("Age: "+str(age))
... print("Role: "+role)
...
>>> profile("Joe")
Name: Joe
Age: 25
Role: guest
>>> profile("Jay",25,"admin")
Name: Jay
Age: 25
Role: admin
>>> profile("Kim",role="admin")
Name: Kim
Age: 25
Role: admin
>>> profile(name="Leo",role="admin")
Name: Leo
Age: 25
Role: admin
⇒ '*...' and '**...' Wildcard Parameters in Function Definitions
⇐ Parameter List in Function Definition Statements
2022-10-26, ∼1940🔥, 0💬
Popular Posts:
How to convert a JSON text string to an XML document with PHP language? Currently, there is no built...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
How to convert JSON Objects to PHP Associative Arrays using the json_decode() function? Actually, JS...