Skip to content

is_port_in_range(port)

Return True if port is a valid port number, otherwise False.

Parameters:

Name Type Description Default
port int

Port to check.

required

Returns:

Type Description
bool

True if port is a valid port number, otherwise False.

Examples:

is_port_in_range(8000)
# True

is_port_in_range(70000)
# False
Source code in src/notwork/is_port_in_range.py
def is_port_in_range(port: int) -> bool:
    """
    Return `True` if `port` is a valid port number, otherwise `False`.

    Args:
        port: Port to check.

    Returns:
        `True` if `port` is a valid port number, otherwise `False`.

    Examples:
        ```python
        is_port_in_range(8000)
        # True

        is_port_in_range(70000)
        # False
        ```
    """
    return is_int(port) and MIN_PORT <= port <= MAX_PORT