Computer Science
Which of the following is not correct in context of Positional and Default parameters in Python functions ?
- Default parameters must occur to the right of Positional parameters.
- Positional parameters must occur to the right of Default parameters.
- Positional parameters must occur to the left of Default parameters.
- All parameters to the right of a Default parameter must also have Default values.
Python Functions
1 Like
Answer
Positional parameters must occur to the right of Default parameters.
Reason — The positional parameters must occur to the left of default parameters because in a function header, any parameter cannot have a default value unless all parameters appearing on its right have their default values.
Answered By
2 Likes
Related Questions
Which of the following function headers is correct ?
- def f(a = 1, b):
- def f(a = 1, b, c = 2):
- def f(a = 1, b = 1, c = 2):
- def f(a = 1, b = 1, c = 2, d):
Which of the following statements is not true for parameter passing to functions ?
- You can pass positional arguments in any order.
- You can pass keyword arguments in any order.
- You can call a function with positional and keyword arguments.
- Positional arguments must be before keyword arguments in a function call.
Which of the following is not correct in context of scope of variables ?
- Global keyword is used to change value of a global variable in a local scope.
- Local keyword is used to change value of a local variable in a global scope.
- Global variables can be accessed without using the global keyword in a local scope.
- Local variables cannot be used outside its scope.
Which of the following function calls can be used to invoke the below function definition ?
def test(a, b, c, d)
- test(1, 2, 3, 4)
- test(a = 1, 2, 3, 4)
- test(a = 1, b = 2, c = 3, 4)
- test(a = 1, b = 2, c = 3, d = 4)