Skip to content

Instantly share code, notes, and snippets.

Embed
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)
@bryomuch

This comment has been minimized.

Copy link

bryomuch commented Feb 9, 2018

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

@testman42

This comment has been minimized.

Copy link

testman42 commented Nov 28, 2018

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
You can’t perform that action at this time.