在python中一个汉字算一个字符,一个英文字母算一个字符

用 ord() 函数判断单个字符的unicode编码是否大于255即可。

s = '我xx们的88工作和生rr活168'
n = 0
for c in s:
    if ord(c) > 255:
        print(c)

  

一般来说,中文常用字的范围是:[\u4e00-\u9fa5]

准确点判断中文字符,可以这样比较:

a = "你好"
b = "</p>你好"
c = 'asdf'
def isAllZh(s):
    '包含汉字的返回TRUE'
    for c in s:
        if '\u4e00' <= c <= '\u9fa5':
            return True
    return False

print(isAllZh(a))
print(isAllZh(b))
print(isAllZh(c))

True
True
False

相关文章:

  • 2022-01-08
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-07-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2021-07-25
  • 2021-12-28
相关资源
相似解决方案