Python para impacientes

Python como usar o clamp_number

January 04, 2020

Clamps num within the inclusive range specified by the boundary values a and b.

If num falls within the range, return num. Otherwise, return the nearest number in the range.

def clamp_number(num,a,b):
  return max(min(num, max(a, b)), min(a, b))
clamp_number(2, 3, 5) # 3
clamp_number(1, -1, -5) # -1

Acesse a Referência original 1: Acesse a Referência original 2: