您好,欢迎来到科传财经网。
搜索
您的当前位置:首页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:
 return None
 return None

Copyright © 2019- keclean.com.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务