# python开发中两个list之间传值示例

## 首先对于一个单层的列表

```a = [ 1,2,3]
b = a
a[0] = a[0] +1
print(a)
print(b)
print(id(a[0]))
print(id(b[0]))
print("*"*20)
a1 = [5,6,7]
b1 = a1.copy()
a1[0] = a1[0] + 1
print(a1)
print(b1)
print(id(a1[0]))
print(id(b1[0]))

```

```[2, 2, 3]
[2, 2, 3]
140729246982592
140729246982592
********************
[6, 6, 7]
[5, 6, 7]
140729246982720
140729246982688
```

## 对于多层列表

```a = [[1,2,4],[3,5,8],[],[]]
b = a.copy()
print("打印数组地址：")
print(id(a))
print(id(b))
print("*"*40)
print("打印内层元素地址：")
print(id(a[0]))
print(id(b[0]))
print(id(a[0][0]))
print(id(b[0][0]))
print("*"*40)
a.append(4)
a[1][0] = a[1][0] + 1
print(a)
print(b)
print(id(a[4]))

```

```打印数组地址：
1938878979528
1938879043976
****************************************

1938877731208
1938877731208
140729246982560
140729246982560
****************************************
[[1, 2, 4], [4, 5, 8], [], [], 4]
[[1, 2, 4], [4, 5, 8], [], []]
140729246982656
```

```import copy
a = [[1,2,4],[3,5,8],[],[]]
# b = a.copy()
b =  copy.deepcopy(a)
```

```import copy
a = [[1,2,4],[3,5,8],[],[]]
# b = a.copy()
b =  copy.deepcopy(a)
print("打印数组地址：")
print(id(a))
print(id(b))
print("*"*40)
print("打印内层元素地址：")
print(id(a[0]))
print(id(b[0]))
print("0"*50)
print(id(a[0][0]))
print(id(b[0][0]))
print("10"*50)
print("\n")
print(a[1][0])
print(b[1][0])
print(id(a[1][0]))
print(id(b[1][0]))
print("10"*50)
print("\n")
# print("*"*40)
# a.append(4)
a[1][0] = a[1][0] + 1
#
# print(a)
# print(b)
# print(id(a[4]))
# print("\n")
print("10"*50)
print(a[1][0])
print(b[1][0])
print(id(a[1][0]))
print(id(b[1][0]))
print("10"*50)
print("\n")
b[1][0] = b[1][0] + 2
print(id(b[1][0]))

```

```打印数组地址：
1696261290248
1696261352200
****************************************

1696257692040
1694368707272
00000000000000000000000000000000000000000000000000
140729133343136
140729133343136
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

3
3
140729133343200
140729133343200
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010
4
3
140729133343232
140729133343200
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

140729133343264
```