python统计中文字符串汉字个数的简单实例代码:
def str_count2(str): count=0 for s in str: # 中文字符范围 if '\u4e00' <= s <= '\u9fff': count = count+1 print(s, end="\t") return count str='祖国万岁' count=str_count2(str) print(count)
python统计中文字符串汉字个数的简单实例代码:
def str_count2(str): count=0 for s in str: # 中文字符范围 if '\u4e00' <= s <= '\u9fff': count = count+1 print(s, end="\t") return count str='祖国万岁' count=str_count2(str) print(count)