From the function calls given below for a function defined as def fun(p,t,r=7, c=8): determine which is valid and which one is invalid. Give reasons.

(i)fun(p=5, t=2)

(ii)fun(c=2, r=7)

(iii)fun (80,p=7,r=2)

 

Answer:

  • (i) fun(p=5, t=2) - This function call is valid as the arguments are mentioned as keyword arguments and the 2 arguments that are not mentioned are default arguments.
  • (ii) fun(c=2, r=7) - This function call is invalid as the required argument ‘p’ is not specified.
  • (iii) fun (80,p=7,r=2) - This function call is invalid as 2 values are specified for argument ‘p’.

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo