python計算字符串長度(中文算2個字符)

txt = '名字12' lenTxt = len(txt) lenTxt_utf8 = len(txt.encode('utf-8')) size = int((lenTxt_utf8 - lenTxt)/2 + lenTxt) print("size = " , size ," ,urf8 = ",lenTxt_utf8," ,len = " ,lenT
相關文章
相關標籤/搜索