python判断有中文字符的方法
python判断有中文字符的方法 看下面的一段代码: >>> a=haha >>> len(a) 4 >>> b=哈哈 >>> len(b) 4 >>> c=unicode(a,gb2312) >>> len(c) 4 >>> d=unicode(b,gb2312) >>> len(d) 2 >>> print a,b,c,d haha 哈哈 haha 哈哈 借助unicode +字符串的长度(b的长度是4,d的长度是2),就可以轻易判断出一个字符串是否有中文字符。是不是很简单?python判断有中文字符的方法 看下面的一段代码: >>> a=haha >>> len(a) 4 >>> b=哈哈 >>> len(b) 4 >>> c=unicode(a,gb2312) >>> len(c) 4 >>> d=unicode(b,gb2312) >>> len(d) 2 >>> print a,b,c,d haha 哈哈 haha 哈哈 借助unicode +字符串的长度(b的长度是4,d的长度是2),就可以轻易判断出一个字符串是否有中文字符。是不是很简单?
