【Python】Python3中的str和bytes

参考文章:Python 3的bytes/str之别

len()函数计算的是str的字符数,如果换成byteslen()函数就计算字节数

>>> len('ABC')
3
>>> len('中文')
2
>>> len(b'ABC')
3
>>> len(b'xe4xb8xadxe6x96x87')
6
>>> len('中文'.encode('utf-8'))
6
原文地址:https://www.cnblogs.com/forzhaokang/p/5723203.html