Jump to content

Determine if a string is numeric: Difference between revisions

Line 3,855:
"inf" -> inf <class 'float'> is_numeric: True str.isnumeric: False
"-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}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.