且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何确定Python中utf-8编码字符串的字节长度?

更新时间:2023-09-17 08:31:16

def utf8len(s):
    return len(s.encode('utf-8'))

在Python 2和3中工作正常.

Works fine in Python 2 and 3.