Computer Science
Assertion (A): In Python, a function can have default arguments.
Reasoning (R): Default arguments in Python functions are assigned values when the function is defined, and they can be used if no value is passed during the function call.
Python Functions
2 Likes
Answer
Both A and R are true, and R is the correct explanation of A.
Explanation — In Python, a function can have default arguments. These default values are specified in the function header during the function definition. The default values for parameters are used only if no value is provided for that parameter in the function call.
Answered By
3 Likes
Related Questions
Write a Python program using two functions area and perimeter to compute the area and perimeter of a rectangle. The program should take length and breadth of the rectangle as input from the user.
Assertion (A): Positional arguments in Python functions must be passed in the exact order in which they are defined in the function signature.
Reasoning (R): This is because Python functions automatically assign default values to positional arguments.
- Both A and R are true, and R is the correct explanation of A.
- Both A and R are true, and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.