在Python中,您可以使用`ord()`函数来获取一个字符的Unicode编码值。以下是如何使用`ord()`函数的示例:
char = 'A'unicode_value = ord(char)print(unicode_value) 输出:65
如果您需要将Unicode编码值转换回对应的字符,可以使用`chr()`函数:
code = 65character = chr(code)print(character) 输出:A

如果您需要处理包含Unicode字符的字符串,并且想要迭代每个Unicode字符,您可以这样做:
s = 'Laut Durkheim ist ein "soziologischer Tatbestand" jede mehr oder weniger [...] unabhängiges Eigenleben besitzt.'for char in s:print(f"Unicode value of '{char}': {ord(char)}")
请注意,在Python 3中,字符串默认是Unicode编码的,所以您可以直接输出Unicode字符,例如:
print('\u00e9') 输出:é
