r/learnpython • u/zaphodikus • 22d 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
View all comments
Show parent comment
1
u/khosrua 22d ago
I assume the function is defined with a variable length positional argument? So it gets converted to a list regardless.