Q. Consider a function with following header:


def info(object, spacing = 10, collapse = 1):


Here are some function calls given below. Find out which of these are correct and which of these are incorrect stating reasons:


a. info( obj1)
b. info(spacing= 20)
c. info( obj2, 12)
d. info( obj11, object = obj12)
e. info( obj3, collapse = 0)
f. info()
g. info(collapse = 0, obj3)
h. info( spacing= 15, object = obj4)


Answer :-


 
(a) Correct obj1 is for positional parameter object; spacing gets its default value of 10 and collapse gets its default value of 1.
(b) Incorrect Required positional argument (object) missing; required arguments cannot be missed.
(c) Correct Required parameter object gets its value as obj2; spacing gets value 12 and for skipped argument collapse, default value 1 is taken.
(d) Incorrect Same parameter object is given multiple values one through positional argument and one through keyword(named) argument.
(e) Correct Required parameter object gets its value as obj3; collapse gets value 0 and for skipped argument spacing, default value 10 is taken.
(f) Incorrect Required parameter object's value cannot be skipped.
(g) Incorrect Positional arguments should be before keyword arguments.
(h) Correct Required argument object gets its value through a keyword argument.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post