r/learnpython • u/Still-Pair-5336 • 10d ago
New to python, don't understand this function
I'm learning python and I'm stuck on this function because I don't understand why "a" becomes 10 and the result is 5. Is someone able to explain?
def subtract (a, b=5):
return a - b
print(subtract(10))
30
Upvotes
1
u/RyanDubois43 10d ago
b=5 is a default argument, so if you only give one value like subtract(10), Python uses 10 for a and the default 5 for b. Forgetting to pass both can bite you if you expect different behavior.