Python*args
Arbitrary Arguments, *args
If you do not know how many arguments that will be passed into your function,add a*
before the parameter name in the function definition.
This way the function will receive atuple of arguments, and can access the items accordingly:
Example
If the number of arguments is unknown, add a*
before the parameter name:
def my_function(*kids):
print("The youngest child is " + kids[2])
my_function("Emil", "Tobias", "Linus")
Try it Yourself »print("The youngest child is " + kids[2])
my_function("Emil", "Tobias", "Linus")
Arbitrary Arguments are often shortened to*args in Python documentations.
Related Pages
Python Functions TutorialFunctionCall a FunctionFunction ArgumentsKeyword Arguments**kwargsDefault Parameter ValuePassing a List as an ArgumentFunction Return ValueThe pass Statement i FunctionsFunction Recursion