Function Notes
Function Notes
display()
(ii) Function with argument(s) but no return value
def calc_square(b):
c=b**2
print(c)
a=4
cal_square(a)
(iii) Function with no argument but returns value(s)
def calc_cube():
n=3
c=n**3
return c
m=calc_cube()
print(m)
(iv) Function with argument(s) and returns value(s)
def calc_square(b):
c=b**2
return c
a=4
s=cal_square(a)
print(s)
Q-5 Explain Positional arguments with the help of an example?
Ans- Positional Arguments ( Required Arguments / Mandatory Arguments): When the function call
statement must match the number and order of arguments as defined in the function definition , this is
called the positional argument matching. In such function calls .
The arguments must be provided for all parameters(Required)
The values of arguments are matched with the parameters, position (order) wise (Positional)
This way of parameter and argument specification is called Positional arguments or Required arguments or
Mandatory arguments as no value can be skipped from function call or order cannot be changed e.g., you
cannot assign value of the first argument to third parameter.e.g,. If function definition is like
def display(a , b , c ) :
……
..….
Then possible function calls for this can be:
display ( x , y , z) # 3 values ( all variables ) passed
display ( 2 , y , z) # 3 values ( literal + variables ) passed
display ( 2 , 5 , 7) # 3 values ( all literals ) passed
In the first function call value 5400 is passed to parameter principal, the value 2 is passed to the second
parameter time and since the third argument rate is missing, its default value 0.10 is used for rate. But if a
function call provides all three arguments as shown in second function call then the principal gets value
6100, time gets 3 and the parameter rate gets value 0.15. That means default values assigned in a function
header are considered only if no value is provided for that parameter in the function call.