0
如果我做的:LEN()与Unicode字符串
print "\xE2\x82\xAC"
print len("€")
print len(u"€")
我得到:
€
3
1
但是,如果我做的:
print '\xf0\xa4\xad\xa2'
print len("")
print len(u"")
我得到:
4
2
在第二个示例中,对于一个字符unicode字符串u“”,len()函数返回2而不是1。
有人可以向我解释为什么会出现这种情况吗?
一样
unicode
我怎么能循环通过包含这种编码的Unicode字符字符串?有些东西像你“”。 – lessthanl0l@ lessthanl0l:尝试像这样:http://stackoverflow.com/questions/7494064/how-to-iterate-over-unicode-characters-in-python-3 –