r/learnpython • • Oct 27 '26

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

-1

u/shift124 Oct 27 '26

You pass 10 to the function as an argument so it becomes a. Ironically a is also hexadecimal version of 10. That has nothing to do with what’s happening here but if you passed 0xA it would be the same thing.

1

u/GustenKusse Oct 27 '26

That's not ironic

1

u/shift124 Oct 28 '26

Maybe bad verbiage. Serendipitous.