【发布时间】:2016-06-16 08:07:16
【问题描述】:
我一直在尝试在 Python 中将十六进制字符串转换为十六进制值,就像您可以将包含整数的字符串转换为整数值一样。我已经尝试了以下
>>> a = '0x25'
>>> b = hex(a)
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
b=hex(a)
TypeError: hex() argument can't be converted to hex
和
>>> b = '20'
>>> int(b)
20
但我还没有找到任何可行的解决方案。
【问题讨论】: