is_positive#
- paramcheckup.numbers.is_positive(number, param_name, kind, kind_name, stacklevel=4, error=True)[source]#
This function checks whether number is a positive number (lower than zero, not included).
- Parameters:
- numberint or float
The number that needs to be checked;
- param_namestr
The name of the parameter that received the variable
- kindstr
The object where param_name is applied (function, method, class, etc.);
- kind_namestr
The name of the object kind;
- stacklevelint, optional
The stacking level (default is
4);- errorbool, optional
Whether to display error text (True, default) or not (False);
- Returns:
- True
If variable value IS positive;
- ValueError
If variable value is NOT positive;
Examples
>>> from paramcheckup import numbers >>> result = numbers.is_positive( number=3.1416, param_name="hypotenuse", kind="function", kind_name="pitagoras", stacklevel=3, error=False, ) >>> print(result) True
>>> from paramcheckup import numbers >>> result = numbers.is_positive( number=0, param_name="hypotenuse", kind="function", kind_name="pitagoras", stacklevel=3, error=False, ) UserWarning at line 2: The `hypotenuse` in function `pitagoras` must be a positive number, but it is equal to `0`.
>>> from paramcheckup import numbers >>> result = numbers.is_positive( number=-273.15, param_name="hypotenuse", kind="function", kind_name="pitagoras", stacklevel=3, error=False, ) UserWarning at line 2: The `hypotenuse` in function `pitagoras` must be a positive number, but it is equal to `-273.15`.