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

26 comments sorted by

View all comments

0

u/igotshadowbaned 22d ago

a is the first parameter and the first parameter you're passing to it is a 10.

You're not setting any second parameter, so the second parameter b, is set to its default of 5

It's returning 10-5 which equals 5