Variable Length Arguments

0

Variable Length Arguments

  • Sometimes we can pass variable number of arguments to our function,such type of arguments are called variable length arguments.

  • We can declare a variable length argument with * symbol   as follows: 

                     def f1(*n):

  • We can call this function by passing any number of arguments including zero number. Internally all these values represented in the form of tuple.

Note: We can mix variable length arguments with positional arguments.  

Note: After variable length argument , if we are taking any other argument then we should provide values as keyword arguments.

  • f1("A","B",10)   ==>Invalid 

  • TypeError: f1() missing 1 required keyword-only argument: 'n1'

Note:- We can declare key word variable length arguments also. For this we have to use **.

  • def  f1(**n): 

We can call this function by passing any number of keyword arguments. Internally these keyword arguments will be stored inside a dictionary. 


 

 

Post a Comment

0Comments
Post a Comment (0)