最近细看python核心编程(以前走马观花过),里面讲到了python缓存的整数的现象,书上说是缓存到100?,还要看实现。每个版本到底能缓存多少呢?
"""
To find the cache range of integer in python under version of this
>>> sys.version
'2.5.4
>>>
"""
var1 = 0
var2 = 0
while True:
if var1 is not var2: #id(var1) != id(var2)
#up
#print 'bingo!:%d' % (var1-1)
#down
print 'bingo!:%d' % (var1+1)
break
#up
#var1 += 1
#var2 += 1
#down
var1 -= 1
var2 -= 1
得出结论:
up:
...
bingo!:256
down:
...
bingo!:-5
[-5,256]
==over==
阅读(2465) | 评论(0) | 转发(0) |