遇到了下面一个问题
```
def demo1(array):
array += [4, 5]
return array
def demo2(array):
array = array + [4, 5]
return array
a = [1, 2, 3]
b = [1, 2, 3]
c = demo1(a)
print('a list is {}\nc list is {}\na is c :{}'.format(a, c, a is c)) # True
# 输出结果
a list is [1, 2, 3, 4, 5]
c list is [1, 2, 3, 4, 5]
a is c :True
d = demo2(b)
print('b list is {}\nd list is {}\nb is d :{}'.format(b, d, b is d)) # False
# 输出结果
b list is [1, 2, 3]
d list is [1, 2, 3, 4, 5]
b is d :False
# 函数内部为什么 array += [4, 5] 与 array = array + [4, 5] 对传入的列表影响结果不同
```
展开