Python Memory Model

前端 未结 4 1766
半阙折子戏
半阙折子戏 2020-12-24 09:00

I have a very large list Suppose I do that (yeah, I know the code is very unpythonic, but for the example\'s sake..):

n = (2**32)**2
for i in xrange(10**7)
          


        
4条回答
  •  渐次进展
    2020-12-24 10:02

    In both examples arr[i] takes reference of object whether it is n or resulting object of i * 2.

    In first example, n is already defined so it only takes reference, but in second example, it has to evaluate i * 2, GC has to allocate space if needed for this new resulting object, and then use its reference.

提交回复
热议问题