我有这个清单:
a_list = [0x00, 0x00, 0x00, 0x00]
Run Code Online (Sandbox Code Playgroud)
当我打印它时,我得到:
print a_list
[0, 0, 0, 0]
Run Code Online (Sandbox Code Playgroud)
但我想:[0x0, 0x0, 0x0, 0x0]或者[0x00, 0x00, 0x00, 0x00],现在没关系.
我试图创建一个函数,如:
def hex_print(the_list):
string = '['
for element in the_list:
if(the_list.index(element) < len(the_list)):
print(str(the_list.index(element)))
string = string + hex(element) + ', '
else:
print(str(the_list.index(element)))
string = string + hex(element) + ']'
print string
Run Code Online (Sandbox Code Playgroud)
但每次打印的消息是:
[0x0, 0x0, 0x0, 0x0,
Run Code Online (Sandbox Code Playgroud)
我认为the_list.index(element)总是返回the_list中第一次出现的元素,而不是元素的实际位置.有没有办法让我得到元素的实际位置?
python ×1