Computer Science, asked by chiragsingh8833, 25 days ago

Consider below given function headers. Identify which of these will cause error and why
(1) def func(a - 1, b):
(ii) def func(a = 1, b, c = 2):
(iii) def func(a -1, b = 1, C = 2):
(iv) def func(a = 1, b = 1, c = 2, d):​

Answers

Answered by parishayzia17
5

Answer:

Ans will be 3rd one

Explanation:

because - - is +

Answered by vishakasaxenasl
0

Answer:

The alternative (ii) will cause the error because it is an invalid function hearder.

(ii) def func(a = 1, b, c = 2):

Explanation:

Functions

Functions are the small block of the code that increases reusability and compatibility in the writing of the code.

In Python language, functions are created with the def keyword.

We can classify the functions into two categories:

  1. Non-Parametrized Functions: When a function doesn't take any argument, it is called a non-parametrized function.
  2. Parametrized Functions: When functions accept arguments, it is called parametrized function.

Here we have a parameterized function. There are some rules that we follow in parametrized function in order to make it a valid function:

  1. First, a function header must be created before it is called the main function.
  2. If the function is having default and non-default parameters both, then default parameters should be written before writing the non-default parameters. Otherwise, the interpreter will be confused about taking the arguments.

In the second option given, def func(a = 1, b, c = 2):

the non-default parameter is written in between default parameters. This will cause an error.

#SPJ3

Similar questions