Computer Science
Assertion (A): Python supports both positional and keyword arguments in functions.
Reasoning (R): Positional arguments are assigned based on their position in the function call, while keyword arguments are assigned based on the name of the parameter.
Python Functions
2 Likes
Answer
Both A and R are true, and R is the correct explanation of A.
Explanation — Python allows both positional and keyword arguments in functions. Positional arguments are passed based on their position in the function call. The first argument passed corresponds to the first parameter in the function definition, the second argument to the second parameter, and so on. While keyword arguments are passed according to the name of the parameter in the function definition.
Answered By
3 Likes
Related Questions
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))
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.
What will be the output of the following code ?
num = [3, 5, 7, 9] def process(): num.append(11) num[0] = num[2] + 1 print(num[0], end = '#') process() num[2] = 14 print(num[2], end = '%')
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#