Determine if a string is numeric: Difference between revisions
Content added Content deleted
Line 3,855: | Line 3,855: | ||
"inf" -> inf <class 'float'> is_numeric: True str.isnumeric: False |
"inf" -> inf <class 'float'> is_numeric: True str.isnumeric: False |
||
"-Infinity" -> -inf <class 'float'> is_numeric: True str.isnumeric: False</pre> |
"-Infinity" -> -inf <class 'float'> is_numeric: True str.isnumeric: False</pre> |
||
===Python: Regular expressions== |
|||
<lang python>import re |
|||
numeric = re.compile('[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?') |
|||
is_numeric = lambda x: numeric.fullmatch(x) != None |
|||
is_numeric('123.0')</lang> |
|||
=={{header|Quackery}}== |
=={{header|Quackery}}== |