python快速简单统计文本中汉字的个数

直接上代码:

str = "[alsdjfkjas.,;'/{)&^%$#@!哈哈*(&^wdjkfjakl哇哇"
count = 0
for s in str:
	if '\u4e00' <= s <= '\u9fff':
		count += 1

核心思想:在utf-8下,用编码范围锁定汉字,排除字符

你可能感兴趣的:(小知识)