python物件的記憶體佔用

lt發表於2020-01-11

集合竟然是列表的4倍

import sys as sys
a = [x for x in range(1000)]
print (sys.getsizeof(a))

4516
a = [x for x in range(1000000)]
print (sys.getsizeof(a))

4348736
set_a=set(a)
print (sys.getsizeof(set_a))

16777332
a=a+a
print (sys.getsizeof(a))

8000036
set_a=set(a)
print (sys.getsizeof(set_a))

16777332

相關文章