pythonzifuchuan/ target=_blank class=infotextkey>python字符串与数字相互转换
1,字符串转换成数字:
复制代码 代码示例:
>>> a = "18"
>>> b = string.atoi(a, 16)
>>> print b
24
>>> a = "0x18"
>>> b = string.atoi(a, 16)
>>> print b
24
>>> a = "18"
>>> c = string .atoi(a)
>>> print c
18
2、数字转换成字符串(接上面):
复制代码 代码示例:
>>> d = "%i"%c # 10进制表示
>>> print d
18
>>> type(d)
<type 'str'>
>>> e = "0x%X"%c #16进制表示
>>> print e
0x12