You may come across a time while learning function in python where a function definition has specified parameter but you want to pass multiple value to the calling function. In that case, you can use variable length argument. It maybe useful to the programmer when the programmers is unsure about how many values to be passed during function call.
Variable length argument is also known as arbitrary arguments in python. To use variable length argument, we simply put *
to the function parameter that you wish to hold multiple values. The following program demonstrates the simple use of such argument.
def multiplication(x,*y):
m=x
for i in y:
m=m*i
print("The required multiplication value is: ",m)
multiplication(2,4,5,6,8)
#Or it can be done as below too:
def multiplication(*y):
m=1
for i in y:
m=m*i
print("The required multiplication value is: ",m)
multiplication(2,4,5,6,8)
The output of this code when executed is as follows: