pylab_ml.common.data.str2num
- str2num(value, base=10, default='')[source]
Translate str to numeric value.
- eg. str2num(“0x1A”) -> 26
str2num(“0b1010”) -> 10 str2num(“”) -> default value (empty string) str2num(“3.14”) -> 3.14 str2num(“Hello”) -> “Hello”
- Parameters:
value (str) – The string to be converted to a numeric value. The function will attempt to parse the string as an integer or a float, and will return the original string if it cannot be parsed as a number.
base (int, optional) – The base to use for parsing integers. Default is 10. If the string starts with “0x” or “0b”, the base will be automatically set to 16 or 2, respectively.
default (any, optional) – The default value to return if the input string is empty or None. Default is an empty string.
- Returns:
The parsed numeric value if the string can be converted to an integer or a float, or the original string if it cannot be parsed as a number. If the input string is empty or None, the specified default value will be returned.
- Return type:
int, float, or str