python-small-examples/md/88.md at master · data-python/python-small-examples

Skip to content

Navigation Menu

Sign in

Appearance settings

Latest commit

File metadata and controls

20 lines (15 loc) · 282 Bytes

@author jackzhenguo
@desc 
@date 2019/5/3

88 字符串字节长度

def str_byte_len(mystr):
    return (len(mystr.encode('utf-8')))

测试:

str_byte_len('i love python')  # 13(个字节)
str_byte_len('字符')  # 6(个字节)