相关疑难解决方法(0)

对于单个Unicode字符串,Python返回长度为2

在Python 2.7中:

In [2]: utf8_str = '\xf0\x9f\x91\x8d'
In [3]: print(utf8_str)

In [4]: unicode_str = utf8_str.decode('utf-8')
In [5]: print(unicode_str)
 
In [6]: unicode_str
Out[6]: u'\U0001f44d'
In [7]: len(unicode_str)
Out[7]: 2
Run Code Online (Sandbox Code Playgroud)

由于unicode_str只包含一个unicode代码点(0x0001f44d),为什么len(unicode_str)返回2而不是1?

python unicode python-2.7 python-unicode

7
推荐指数
1
解决办法
1302
查看次数

标签 统计

python ×1

python-2.7 ×1

python-unicode ×1

unicode ×1