What is the best possible way to check if a string can be represented as a number in Python?
The function I currently have right now is:
def is_numb
str.isnumeric()
Return
True
if all characters in the string are numeric characters, and there is at least one character,False
otherwise. Numeric characters include digit characters, and all characters that have the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION ONE FIFTH. Formally, numeric characters are those with the property value Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric.
str.isdecimal()
Return
True
if all characters in the string are decimal characters and there is at least one character,False
otherwise. Decimal characters are those that can be used to form numbers in base 10, e.g. U+0660, ARABIC-INDIC DIGIT ZERO. Formally a decimal character is a character in the Unicode General Category “Nd”.
Both available for string types from Python 3.0.