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
5
Answer:
Ans will be 3rd one
Explanation:
because - - is +
Answered by
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:
- Non-Parametrized Functions: When a function doesn't take any argument, it is called a non-parametrized function.
- 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:
- First, a function header must be created before it is called the main function.
- 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
India Languages,
12 days ago
English,
12 days ago
Political Science,
25 days ago
Math,
25 days ago
Math,
8 months ago
Social Sciences,
8 months ago