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 –