对于④,python isdigit()为True,但int()失败

时间:2014-10-09 18:22:57

标签: python unicode

和④有什么区别?

>>> u''.isdigit()
True
>>> int(u'')
4
>>> u'④'.isdigit()
True
>> int(u'④')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '④'

注意:上面是python3上的输出。在python last上给出了这个例外:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'decimal' codec can't encode character u'\u2463' in position 0: invalid decimal Unicode string

0 个答案:

没有答案