Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Limiting input number between minimum and maximum values range in Python
def limit(num, minimum=1, maximum=255):
"""Limits input 'num' between minimum and maximum values.
Default minimum value is 1 and maximum value is 255."""
return max(min(num, maximum), minimum)
Copy link

bryomuch commented Feb 9, 2018

wonderful ,just worderful, this saved me a lot of time

Copy link

Nice, exactly what I was looking for. Thank you very much for saving this to Github 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment