Skip to content

ItIs

Tools for determining something.

The module contains the following functions:

  • is_number - Check if a string is a number.

is_number(value)

Check if a string is a number.

Only decimal numbers.

Examples:

>>> from xloft import is_number
>>> is_number("123")
True

Parameters:

Name Type Description Default
value str

Some kind of string.

required

Returns:

Type Description
bool

True, if the string is a number.

Source code in src/xloft/itis.py
def is_number(value: str) -> bool:
    """Check if a string is a number.

    Only decimal numbers.

    Examples:
        >>> from xloft import is_number
        >>> is_number("123")
        True

    Args:
        value (str): Some kind of string.

    Returns:
        True, if the string is a number.
    """
    try:
        float(value)
        return True
    except ValueError:
        return False