Robotics & Artificial Intelligence
In the following code snippet, what does 5 in the argument list represent?
def add(x, y=5):
return x + y
- return value
- default value
- input value
- None of these
Python Functions
1 Like
Answer
default value
Reason — Default arguments allow a function parameter to have a predefined value. In the given function definition def add(x, y=5):, the value 5 is assigned to parameter y as its default value, which is used when no value is provided for y during the function call.
Answered By
2 Likes
Related Questions
What is the purpose of return statement in Python functions?
- It is used to terminate the execution of a function
- It is used to define the output of a function
- It is used to import modules into a function
- None of these
What would be output of the following code snippet?
def multiply(x, y=2): return x * y result = multiply(5) print(result)- 5
- 10
- 2
- Error
Which keyword is used to define function with variable length arguments?
- *args
- **kwargs
- *var
- Both a and b
Which of the following is not a built-in function in Python?
- input()
- print()
- len()
- add()