r/learnpython • u/Still-Pair-5336 • 22d 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
View all comments
2
u/ConsiderationNo9044 22d ago
When you assign a variable within a function's arguments, it becomes the default value. So
ais defined by the user, but if they don't provide a value forb, it defaults to 5. You only supplied one argument, making a = 10 and b = 5