【发布时间】:2019-10-22 14:06:57
【问题描述】:
我正在通过一个非常简单的 python3 指南来使用字符串操作,然后我遇到了这个奇怪的错误:
In [4]: # create string
string = 'Let\'s test this.'
# test to see if it is numeric
string_isnumeric = string.isnumeric()
Out [4]: AttributeError Traceback (most recent call last)
<ipython-input-4-859c9cefa0f0> in <module>()
3
4 # test to see if it is numeric
----> 5 string_isnumeric = string.isnumeric()
AttributeError: 'str' object has no attribute 'isnumeric'
问题在于,据我所知,str DOES 有一个属性 isnumeric。
【问题讨论】:
-
不在 Python 2 中,将该字符串更改为 unicode 字符串。
-
尝试改用
isdigit。 -
找到答案:文本在Py3中默认为unicode。 stackoverflow.com/questions/16863696/…
-
将其发布为带有解释的答案。接受。问题已解决。
标签: python python-3.x