如何将列表中的字符更改为十六进制数字?

How to change characters in a list to hex numbers?

key = input()

a = list(str(key))
print(a)

有谁知道如何更改 a 列表以在其中获取十六进制数字?示例:

key = "abc"
>> ["a", "b", "c"]

但不是那些字母的十六进制数字。

谢谢。

使用 ord to get the int representation of a character, and hex 获取该 int 的十六进制表示。

>>> [hex(ord(c)) for c in "abc"]
['0x61', '0x62', '0x63']