m = 10
a = 10
print(id(m))
print(id(a))
'''输出
140713874176728
140713874176728
'''
print()
a = 1
b = 2
c = 3
d = a+b
print('a(1)\t'+str(id(a)))
print('b(2)\t'+str(id(b)))
print('c(3)\t'+str(id(c)))
print('d(a+b)\t'+str(id(d)))
'''
a(1) 140713904781752
b(2) 140713904781784
c(3) 140713904781816
d(a+b) 140713904781816
'''
print()
l = [1,1,1]
ll = [1,1,1]
print('l\t'+str(id(l)))
print('ll\t'+str(id(ll)))
print('l[0](1)\t'+str(id(l[0])))
print('l[1](1)\t'+str(id(l[1])))
'''
l 2141254244608
ll 2141254242688
l[0](1) 140713903405496
l[1](1) 140713903405496
'''
print()
aa = []
bb = []
print(id(aa))
print(id(bb))
'''
1460613077248
1460613075328
'''
print()
#字面量(常量,10之类的)的地址是固定的
li1 = []
j1 = 20
li1.append(j1)
print("j1(20)\t"+str(id(j1)))
print("li1[0]\t"+str(id(li1[0])))
print(li1)
j1 = 30
print(li1)
print("j1(30)\t"+str(id(j1)))
'''
j1(20) 140713904782360
li1[0] 140713904782360
[20]
[20]
j1(30) 140713904782680
'''
print()
li2 = []
j = [1,2]
jj = [1,2]
li2.append(j)
li2.append(jj)
print(li2)
print('j\t'+str(id(j)))
print('jj\t'+str(id(jj)))
print('li2\t'+str(id(li2)))
print('li2[0]\t'+str(id(li2[0])))
print('li2[1]\t'+str(id(li2[1])))
'''
[[1, 2], [1, 2]]
j 1719899061696
jj 1719899159552
li2 1719899062144
li2[0] 1719899061696
li2[1] 1719899159552
'''
# ~ j[0] = 9
# ~ print(li2)
# ~ '''
# ~ [[1, 2]]
# ~ [[9, 2]]
# ~ '''
# ~ j = [1,2,3]
# ~ print(li2)
# ~ '''
# ~ [[1, 2]]
# ~ [[1, 2]]
# ~ '''
# ~ j.append(3)
# ~ print(li2)
# ~ '''
# ~ [[1, 2]]
# ~ [[1, 2, 3]]
# ~ '''
标签:2024.1,li2,Python,18,j1,li1,str,print,id
From: https://www.cnblogs.com/l25428455/p/17972239