Arbitrary Argument lists in Python.

Consider the function definition:
def mapp(fun,first,*second): (A function that is defined to implement the properties of the ‘map’ function

Here the function ‘mapp’ consists of three arguments passed to it. Out of this ,the third argument (second) is the arbitrary argument list. The argument is itself optional and can be passed with different lists or tuples ranging from zero to any number of lists.
The length of the arbitrary listed argument would be zero if no arguments are passed to it.(len(second)=0).

The call to the above function would be as follows:
mapp(sqr,a)

OR

mapp(add,a,b,c)

OR

mapp(mul,a,b)

where a,b,c are any lists.
and ‘sqr’,’add’,’mul’ are functions.

Suppose the call to the function be
mapp(mul,a,b,c)

The lists b,c are passed as arguments to the function ‘mapp’ via the formal parameter ‘second’ (arbitrary listed argument).
Now second[0]=b
second[1]=c.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s