Computer Science, asked by mahdiabdullah, 6 months ago


22
Which of the following function headers is correct?
(1 Point)
A. def fun(a + 2,b = 3.c)
B. def fun(a = 2,b. C-3)
c. det fun(a, b = 2,c = 3)
D. def fun(a, b, c*3, d)​

Answers

Answered by letmeanswer12
1

"Option C:def fun(a, b = 2,c = 3)".                

Explanation :  

In the python def function, all necessary parameters must be placed before any default arguments. Because they are required, whereas default arguments are not.

Syntactically, it would be hard for the interpreter to decide which values fit which arguments if mixed modes were allowed. The syntax error is raised, if arguments are not given in the correct order. So, option C is correct.

All the other options are not given in the correct order, it may cause a syntax error.

Answered by SaurabhJacob
0

c. def fun(a, b=2, c=3) is the correct option.

By providing the value to the variables in the function header or definition will convert that function to the function with default arguments.

There are some rules to be followed are,

  • The default values cannot be provided to any random variable inside the function definition.
  • It can only be assigned in sequential order starting from the right-most side.

The above rules are followed in only one of the options.

And, in the other options are having operations inside it that are not allowed by the compiler.

Similar questions