Explanation:
๐น Step 1: Define Function
def f(x, y=2): return x*y
Function f takes:
x → required argument
y → default value = 2
It returns:
๐ x * y
๐น Step 2: First Function Call
f(3)
Only x is provided → x = 3
Default y = 2 is used
๐ Calculation:
3 * 2 = 6
๐น Step 3: Second Function Call
f(3, None)
Now:
x = 3
y = None (default is overridden ❗)
๐ Calculation:
3 * None
⚠️ Important Concept
None is not a number
Multiplication with None is not allowed
๐ So Python raises:
TypeError: unsupported operand type(s)\
๐น Step 4: Print Statement
print(f(3), f(3, None))
First call → prints 6
Second call → ❌ causes error
๐ Output:
Error

0 Comments:
Post a Comment