需求:统计给定文本的字数:包括中英文
本来是这样写的,但是发现行不通,
代码:
def GetWordNums(text):
num = 0
for i in text:
if i not in ' \n!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~':
num = num +1
return num
希望大家帮忙指点下
以下方法可以使用:
len("测试".encode("gbk").decode("gbk"))
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
快使用Python 3,哼哼哈兮~