Created
June 26, 2016 06:27
-
-
Save baybatu/269296fe1d530f0defff7b6454222bc0 to your computer and use it in GitHub Desktop.
Limiting input number between minimum and maximum values range in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
wonderful ,just worderful, this saved me a lot of time