isnumeric 和 isdecimal 未按预期运行

isnumeric & isdecimal not behaving as expected

在 python 中,字符串有一个方法 isnumericisdigit

我的(错误)印象是 isnumericisdecimal 会 return True 用于 123.45 等字符串,否则为 false。我是 运行 python 的以下版本:

Python 3.4.2 (default, Jan  7 2015, 11:54:58) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin

我发现 isnumericisdecimal return 如果字符串中的所有字符都是整数则为真,但如果存在 '.'(点)则为假。是什么导致了这种行为?不应该 '123.45'.isnumeric() return True?

>>> mystr_a = '123.45'
>>> mystr_b = '123'
>>> 
>>> mystr_a.isnumeric()
False
>>> mystr_a.isdecimal()
False
>>> mystr_b.isnumeric()
True
>>> mystr_b.isdecimal()

Python documentation中所定义,isnumericreturnsTrue如果字符串内的所有字符都是数字,否则False。点不被视为数字。