如何区分指数和普通数

How to distinguish exponent and ordinary number

下面两个表达式returnTrue

'2'.isdigit()
chr(178).isdigit()

后者为指数

我正在寻找一种方法来区分所有数字

这是as documented

str.isdigit()

Return true if all characters in the string are digits and there is at least one character, false otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.

如果您想检查 python 是否能够将字符串解析为数字,惯用的方法是使用 try-except。

def is_really_digit(s):
   try:
      int(s)
      return True
   except ValueError:
      return False