Is there a more Pythonic way to achieve this:
result = #...real value from elsewhere
max_value = 1
min_value = 0
if result > max_value:
result = max_value
elif result < min_value:
result = min_value
return result
Not sure how to explain it in words so I hope it's clear. Thanks
You can use the min and max functions:
result = min(max_value, max(min_value, result))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With