| 源 对象 | 引用后 对象 | 处理后 引用对象 | 引用后源对象 | |||||
|---|---|---|---|---|---|---|---|---|
| ID | 值 | ID | 值 | ID | 值 | ID | 值 | |
| test01 | 2002431216576 | [1, 2, 3] | 1590914157696 | [1, 2, 3] | — | — | 1590914157696 | [1, 2, 3] |
| test02 | 2572513741888 | [1, 2, 3] | 2572513741888 | [1, 2, 3] | 2572513741888 | [1, 2, 3, 2] | 2572513741888 | [1, 2, 3, 2] |
| test03 | 2316473231952 | 10 | 2316473231952 | 10 | 2316473231952 | 10 | ||
| test04 | 2422428559952 | 10 | 2422428559952 | 10 | 2316473231952 | 20 | 2422428559952 | 10 |
# test01验证参数传递后,源与引用源ID及value变化def test01(b):a = bprint('a的值是:{}'.format(a))print('a的类型是:{}'.format(id(a)))# 可变对象b =[1, 2, 3]print(b)print(id(b))test01(b)print(b)print(id(b))
# 验证处理前后变化def test02(b):a = bprint('处理前a的值为{}'.format(a))print('处理前a的ID为{}'.format(id(a)))a.append(2)print('a的值是:{}'.format(a))print('a的id是:{}'.format(id(a)))# 可变对象b =[1, 2, 3]print(b)print(id(b))test02(b)print(b)print(id(b))
- 对join函数的使用有问题。 ```python def test03(b): a = b print(‘a的值是:{}’.format(a)) print(‘a的id是:{}’.format(id(a)))
不可变对象
b =10
print(b) print(id(b)) test03(b) print(b) print(id(b))
10 2316473231952 a的值是:10 a的id是:2316473231952 10 2316473231952
```pythondef test04(b):a = bprint('a的值是:{}'.format(a))print('a的id是:{}'.format(id(a)))a = a+10print('a的值是:{}'.format(a))print('a的id是:{}'.format(id(a)))# 不可变对象b =10print(b)print(id(b))test04(b)print(b)print(id(b))**********************************102422428559952a的值是:10a的id是:2422428559952a的值是:20a的id是:2422428560272102422428559952
