python 如何判断中文的字符串长度

环境:python 2

line = "最近还好吗"
print len(line.decode("utf-8"))

结果:

5

备注:
直接使用代码:

print len(line)

会得到错误的答案。

发布了22 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/helloworld987456/article/details/95376565