import string
allChars = string.digits+string.lowercase #get a list of all the 'characters' which represent digits
def toInt(srep,base):
charMap = dict(zip(allChars,range(len(allChars)))) #map each 'character' to the base10 number
num = 0 #the current total
index = len(srep)-1 #the current exponent
for digit in srep:
num += charMap[digit]*base**index
index -= 1
return num
假设number以16为基数,那么这个函数返回与该数字等价的
int
。在看这个definition of int method
它的工作原理如下:
解释“a16”的一些调试打印的过程是:
^{pr2}$相关问题 更多 >
编程相关推荐