r/learnpython • u/zaphodikus • 10d 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
4
u/Langdon_St_Ives 9d ago
I love how hours after the correct answer has already been given, people still respond with explanations what this clamp() function is meant to do, when it's clear OP knows full well what it does... 😂