python包含中文字符串长度
来源:动视网
责编:小采
时间:2020-11-27 14:27:54
python包含中文字符串长度
python包含中文字符串长度:python包含中文字符串长度一个中文utf8编码后是占3个字符,所以求长度的函数可以这样写def str_len(str): try: row_l=len(str) utf8_l=len(str.encode('utf-8')) return (utf8_l-row_l)/2+row_l except:
导读python包含中文字符串长度:python包含中文字符串长度一个中文utf8编码后是占3个字符,所以求长度的函数可以这样写def str_len(str): try: row_l=len(str) utf8_l=len(str.encode('utf-8')) return (utf8_l-row_l)/2+row_l except:

python包含中文字符串长度
一个中文utf8编码后是占3个字符,所以求长度的函数可以这样写
def str_len(str):
try:
row_l=len(str)
utf8_l=len(str.encode('utf-8'))
return (utf8_l-row_l)/2+row_l
except:
return None
return None
python包含中文字符串长度
python包含中文字符串长度:python包含中文字符串长度一个中文utf8编码后是占3个字符,所以求长度的函数可以这样写def str_len(str): try: row_l=len(str) utf8_l=len(str.encode('utf-8')) return (utf8_l-row_l)/2+row_l except: