2019-07-09
阅读量:
498
范围函数的储存对象
存储所述的可变范围()由范围创建需要更多的存储器相比,使用可变的xrange存储范围()。其基本原因是range()的返回类型是list,xrange()是xrange()对象。
# Python code to demonstrate range() vs xrange()
# on basis of memory
import sys
# initializing a with range()
a = range(1,10000)
# initializing a with xrange()
x = xrange(1,10000)
# testing the size of a
# range() takes more memory
print ("The size allotted using range() is : ")
print (sys.getsizeof(a))
# testing the size of a
# range() takes less memory
print ("The size allotted using xrange() is : ")
print (sys.getsizeof(x))






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论