KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

What would be output of the following code snippet?

def multiply(x, y=2): 
    return x * y 
result = multiply(5) 
print(result)
  1. 5
  2. 10
  3. 2
  4. Error

Python Functions

2 Likes

Answer

10

Reason — Default arguments are used when a value is not provided during the function call. In the given function multiply(x, y=2), the parameter y has a default value of 2. When the function is called as multiply(5), the value 5 is assigned to x and the default value 2 is assigned to y. Therefore, the function returns 5 × 2 = 10, which is printed as the output.

Answered By

3 Likes


Related Questions