Tools, FAQ, Tutorials:
'*...' and '**...' Wildcard Parameters in Function Definitions
What are "*..." and "**..." Wildcard Parameters in Function Definitions?
✍: FYIcenter.com
If you want to define a function that receives a unknown number of parameters,
you have to use the "*..." and "**..." Wildcard Parameters in the "def" statement
using the following syntax:
def func_name(named_parameter,..., *list_params, **dict_params)
Where:
Here is good example of a function with "*..." and "**..." wildcard parameters:
>>> def shopping(sugar=2, milk=4, *onePieces, **byKilos):
... print("Sugar: "+str(sugar)+" bags")
... print("Milk: "+str(milk)+" bottles")
... for item in onePieces:
... print(str(item)+": 1 piece")
... for item in byKilos:
... print(str(item)+": "+str(byKilos[item])+" kilos")
...
>>> shopping()
Sugar: 2 bags
Milk: 4 bottles
>>>
>>> shopping(1, 3, "Bread", "Pineapple")
Sugar: 1 bags
Milk: 3 bottles
Bread: 1 piece
Pineapple: 1 piece
>>>
>>> shopping(1, 3, "Bread", "Pineapple", Grape=2, Coffee=1)
Sugar: 1 bags
Milk: 3 bottles
Bread: 1 piece
Pineapple: 1 piece
Grape: 2 kilos
Coffee: 1 kilos
⇒ Function Parameter Default Expression Executed Only Once
⇐ Calling Function with Keyword Parameters
2022-10-26, ∼5903🔥, 0💬
Popular Posts:
What is EPUB 3.0 Metadata "dcterms:modified" property? EPUB 3.0 Metadata "dcterms:modified" is a req...
How to start Docker Daemon, "dockerd", on CentOS systems? If you have installed Docker on your CentO...
Where to find tutorials on Microsoft Azure services? Here is a large collection of tutorials to answ...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...
What is EPUB 3.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 3.0 Metadata "dc:publisher" ...