I have a value that's need to be greater than some threshold. Right now I use it like this:
value = int(input())
threshold = 10
value = threshold if value < threshold else value
Are there any better ways to do it? Is it "Pythonic" enough?
I have a value that's need to be greater than some threshold. Right now I use it like this:
value = int(input())
threshold = 10
value = threshold if value < threshold else value
Are there any better ways to do it? Is it "Pythonic" enough?
You can use max()
function (and there's min()
if your threshold should cap the value)
value = max(threshold, value)