Arbitrary arguments function in python



Arbitrary arguments allows us to give zero or multiple parameters to the function. If we don't know how many parameters are going to use, then we go for Arbitrary arguments.


In Arbitrary arguments each and every elements are stored in list format.



Syntax:



def function_name(* arguments):

        #body of the method







Example-1
def colors_name(*colors):
    
    print(colors)

colors_name( "Blue", "Black", "Red", "Green")


Output



('Blue', 'Black', 'Red', 'Green')







Example-2
def add(* n):
    
    s = 0
    
    for i in n:
        
        s = s+i
        
    print(s)




add( 1, 2, 3)

add( 4, 5, 6, 7)


Output



6
22