/ Python

Python: 变量的内存分析

[root@iZ23pynfq19Z ~]# cat 2.py
s = [1, 2, 3, 4, 5]
i = 0
g = i = s[i] = 3
[root@iZ23pynfq19Z ~]# python -m dis 2.py
1 0 LOAD_CONST 0 (1)
3 LOAD_CONST 1 (2)
6 LOAD_CONST 2 (3)
9 LOAD_CONST 3 (4)
12 LOAD_CONST 4 (5)
15 BUILD_LIST 5
18 STORE_NAME 0 (s)

2 21 LOAD_CONST 5 (0)
24 STORE_NAME 1 (i)

3 27 LOAD_CONST 2 (3)
30 DUP_TOP
31 STORE_NAME 2 (g)
34 DUP_TOP
35 STORE_NAME 1 (i)
38 LOAD_NAME 0 (s)
41 LOAD_NAME 1 (i)
44 STORE_SUBSCR
45 LOAD_CONST 6 (None)
48 RETURN_VALUE