How about something a little different:
a = (1, x, 100)[-(x<1)+1+(x>100)]
or if you define your limits as
lo, hi = (1, 100) a = (lo, x, hi)[-(x<lo)+1+(x>hi)]
Or change your details and look more elegant:
a = (x,lo,hi)[(x<lo)-(x>hi)]
This is possible in python because booleans behave like the values 0 and 1, allowing the math inside [] to get the correct tuple index.
source share