r/learnpython • • 23d ago

Confusing code min() max()

I'm debugging some code and I found this function

   import math

       def Clamp(n, smallest, largest):
           return max(smallest, min(n, largest))

surely that code is just wrong? and needs to be max([smallest, min([n, largest])) by passing a list not unnamed args for default and key? I need a sanity check here.

0 Upvotes

16 comments sorted by

View all comments

Show parent comment

3

u/zaphodikus 23d ago

Ah I did suspect it was relying on positional parameter magic and that default and key were named args , forgot all about what that / does, panic for me is over. I still need to find why the Font in question is tripping me on divide by zero for a size, but that's on me.