a = 255
#use a hexadecimal format string to display the value of a - prints ff
print "%x" % a
#create a function that takes a value and returns its hexadecimal representation
tohex = lambda x : '%x' % x
#call the function - prints ff
print tohex(255)
在字符串格式表示法中,“%x”是十六进制输出的placeholder。你知道吗
函数接受一个值并将其格式化为十六进制字符串。你知道吗
它不是“十进制到十六进制”,而是“以十六进制表示法作为字符串返回(无论给定什么)”。你知道吗
例如
相关问题 更多 >
编程相关推荐