热线电话:13121318867

登录
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.0000
6
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子