Python Programming – Compound statement Functions Argument

In this Page, We are Providing Python Programming – Compound statement Functions Argument. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Python Programming – Compound statement Functions Argument

Argument

The argument is the value passed to a function (or method) while calling the function. There are two types of arguments:

Keyword argument

Keyword argument is an argument preceded by an identifier (e.g. name=) in a function call or passed as a value in a dictionary preceded by **. For example, 10, 20, 30, and 40 are keyword arguments in the following calls to summation ( ) function:

>>> def summation( aa , bb , cc , dd ) : 
. . .                    print ' aa : ' , aa
. . .                    print ' bb : ' , bb
. . .                    print ' cc : ' , cc
. . .                    print ' dd : ' , dd
. . .                    total=aa+bb+cc+dd
. . .                    return total
. . .
>>> sumupl=summation( bb=20 , dd=40 , aa=10 , cc=30 )
aa : 10
bb : 20
cc : 30
dd : 40 
>>> print ' Sum is: ' , sumupl 
Sum is : 100
>>> sumup2=summation(** { ' bb ' : 20 , ' dd ' : 40 , ' aa ' : 10 , ' cc ' : 30 } ) 
aa : 10
bb : 20 
cc : 30
dd : 4 0
>>> print 'Sum is:',sumup2 
Sum is: 100

Positional argument

Positional argument is an argument that is not a keyword argument. Positional arguments can appear at the beginning of an argument list and can also be passed as elements of an iterable preceded by *. For example, 10, 20, 30 and 40 are positional arguments in the following calls to summation ( ) function:

>>> def summation ( aa , bb , cc , dd ): 
. . .           print ' aa : ' , aa
. . .           print ' bb : ' , bb
. . .           print ' cc : ' , cc
. . .           print ' dd  : ', dd
. . .           total=aa+bb+cc+dd
. . .           return total
>>> sumup3=summation( 10 , 20 , 30 , 40 )
aa : 10
bb : 20
cc : 30
dd : 40
>>> print 'Sum is:',sumup3 
Sum is : 100
>>> sumup4=summation( * ( 10 , 20 , 30 , 40 ) )
aa : 10
bb : 20
cc : 30
dd : 40
>>> print ' Sum is :  ',sumup4 
Sum is : 100