1 结论: 全用xrange,除非你需要使用返回的列表 2 实验一:性能对比 实验环境:win7 ,64位系统 python2.7 import time StartTime=time.time() count =0 for i in range (100000000): # 这里的8个零 内存变动峰值2555,000kb ,耗时 129s count=count+1 EndTime=time.time() print "cost time is:",(EndTime-StartTim…
python中的range()函数的功能hen强大,所以我觉得很有必要和大家分享一下 就好像其API中所描述的: If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates arithmetic progressions 下面是我做的demo: #如果你需要遍历一个数字序列,可以是使用python中内建的函数range() #如下面…
by Harrison Feng in Python 无论是range()还是xrange()都是Python里的内置函数.这个两个内置函数最常用在for循环中.例如: >>> for i in range(5): ... print i ... 0 1 2 3 4 >>> for i in xrange(5): ... print i ... 0 1 2 3 4 >>> range()和xrange() 在Python 2里是两种不同的实现.但是在P…