回覆列表
-
1 # 使用者1053164055079
-
2 # 使用者3878603139388
硬編碼行不?
# -*- coding: cp936 -*-
para = "20133233"
new_para = ""
if not len(para)%2:
print para
for i in range(0,len(para),2):
new_para= new_para + "\\x"+para[i:i+2]
else:
print "字串位數不正確!"
print new_para
十六進位制以兩位的格式列印輸出比較好檢視,所以參考了willenhu的回答,做了些修改:
1
2
3
4
5
6
array = [1,2,3,10,11,12]
print(array)
hex_array = []
for item in array:
hex_array.append("0x%02x"%item)
print(hex_array)
輸出如下
1
2
[1, 2, 3, 10, 11, 12]
["0x01", "0x02", "0x03", "0x0a", "0x0b", "0x0c"]