r/learnpython • • 29d 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

26 comments sorted by

View all comments

25

u/Designer-Ad-2136 29d ago

Change 'b=5' to 'b=1' and see what happens.

Also, try this to understand what that default value is doing by printing: 'subtract(5, 1)'

2

u/Vegetable_Soil_6707 29d ago

solid suggestion, once they see the output change itll just click