python中的字符串和int类型互转可以说是所有语言里面最简单的了,直接用str
和int
方法即可:
nNum = 9999999
print str(nNum)
strNum = "99999999"
print int(strNum)
很简单就能实现转换,而且也无需考虑数据大小越界的问题:
bigNum = "999999999999999999999999999999999999999999999999999999999999"
print int(bigNum) + 1 # 1000000000000000000000000000000000000000000000000000000000000
此处评论已关闭