Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中十六进制列表的字符串_Python - Fatal编程技术网

Python中十六进制列表的字符串

Python中十六进制列表的字符串,python,Python,我有一个输入字符串(例如:“hello”),希望将其转换为十六进制字节列表 十六进制中的“hello”是68656C6F,我正在尝试创建[0x68,0x65,0x6c,0x6c,0x6f] 在Python中执行此操作的最佳方法是什么?将ord与hex一起使用: [hex(ord(i)) for i in "hello"] 输出: ['0x68', '0x65', '0x6c', '0x6c', '0x6f'] 我该如何将其列为十六进制类型的列表?“hello”]中i的[h

我有一个输入字符串(例如:“hello”),希望将其转换为十六进制字节列表

十六进制中的“hello”是68656C6F,我正在尝试创建[0x68,0x65,0x6c,0x6c,0x6f]


在Python中执行此操作的最佳方法是什么?

ord
hex
一起使用:

[hex(ord(i)) for i in "hello"]
输出:

['0x68', '0x65', '0x6c', '0x6c', '0x6f']

我该如何将其列为十六进制类型的列表?“hello”]中i的[hex(ord(i))的输出是字符串列表。