-
-
Save Cactus64k/a0846e67284e7dd5fb0d6a1564ecb8ac 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment