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
3 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
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.
What will be the output of the following code ?
c = 10 def add(): global c c = c + 2 print(c, end = '#') add() c = 15 print(c, end = '%')
- 12%15#
- 15#12%
- 12#15%
- 12%15#
What will be the output of the following code ?
def process_data(lst, dct): result = [] for i in lst: if i in dct: result.append(dct[i] * i) else: result.append(i ** 2) return result lst = [1, 2, 3, 4] dct = {2: 5, 3: 10} print(process_data(lst, dct))
Identify the errors from the code below.
def is_prime(n): if n < 2: return False else: for i in range(2, n) if n % i = 0: return false return True