Functional Weave
Code in TypeScript

net.port@1.0.0

impl/python/is_port.py

334 bytes · the Python implementation · view raw

def is_port(value: int) -> bool:
    """Whether a number is a usable TCP or UDP port: a whole number from 1 to
    65535. Port 0 is reserved (RFC 6335) and asks the operating system to pick
    one, so it is never a port to connect to.
    """
    return isinstance(value, int) and not isinstance(value, bool) and 1 <= value <= 65535