python计算字符、汉字的长度 1 python中1个字母占8byte c = 'abc' print(len(c)) print(len(c.encode('utf-8'))) print(len(c.encode('gbk'))) 运行效果: 2 1个汉字,utf-8方式占3byte,gbk方式占2byte c = '花花' print(len(c)) print(len(c.encode('utf-8'))) print(len(c.encode('gbk'))) 运行效果: