s = input('输入字符串:')
result = ''
for c in s:
    if '一' <= c <= '鿿':  # 判断是否为汉字
        result += c + '=' + hex(ord(c)).replace('0x', '') + ' '
print(result)

运行结果:

输入字符串:abe 天才就是入迷 good123
天=4476 才=1837 就=3045 是=4239 入=4075 迷=3552
Python 获取字符串中所有汉字的区位码

原文地址: https://www.cveoy.top/t/topic/nE88 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录