Computer Science
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)
Answer
test(1, 2, 3, 4)
test(a = 1, b = 2, c = 3, d = 4)
Reason —
- The function call
test(1, 2, 3, 4)
passes four positional arguments 1, 2, 3, and 4 to the function. - The function call
test(a = 1, b = 2, c = 3, d = 4)
passes four keyword arguments, explicitly stating the parameter names (a, b, c, d) and their corresponding values.
Related Questions
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.
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 will cause Error while invoking 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)
For a function header as follows :
def Calc(X,Y = 20):
Which of the following function calls will give an error ?- Calc(15, 25)
- Calc(X = 15, Y = 25)
- Calc(Y = 25)
- Calc(X = 25)