NumList1 = [1,2,3] NumList2 = ['a','b','c'] NumList1.append(NumList2) print("列表2append到列表1:",NumList1) print('第四个元素为',NumList1[3]) NumList1 = [1,2,3] NumList1.extend(NumList2) print("列表2extend到列表1:",NumList1)
输出结果为:
列表2append到列表1: [1, 2, 3, [‘a’, ‘b’, ‘c’]]
第四个元素为 [‘a’, ‘b’, ‘c’]
列表2extend到列表1: [1, 2, 3, ‘a’, ‘b’, ‘c’]
NumList1 = [1,2,3] NumList2 = ['a','b','c'] NumList1.append(NumList2) NumList2[0] = '更改第一个元素' print('拷贝问题',NumList1) NumList1 = [1,2,3] NumList2 = ['a','b','c'] NumList1.extend(NumList2) NumList2[0] = '更改第一个元素' print('拷贝问题',NumList1)
输出结果为:
拷贝问题 [1, 2, 3, [‘更改第一个元素’, ‘b’, ‘c’]]
拷贝问题 [1, 2, 3, ‘a’, ‘b’, ‘c’]
原文链接:https://blog.csdn.net/weixin_36285139/article/details/110950042