extend() 与append()的区别
2019-01-22 本文已影响3人
yimengtianya1
attend()是延展列表,append()是将后面的当做一个元素添加至列表。
a = [1,2,3]
b = [4,5,6]
a.extend(b)
print(a)
>>>[1, 2, 3, 4, 5, 6]
a = [1,2,3]
b = [4,5,6]
a.append(b)
print(a)
>>>[1, 2, 3, [4, 5, 6]]
attend()是延展列表,append()是将后面的当做一个元素添加至列表。
a = [1,2,3]
b = [4,5,6]
a.extend(b)
print(a)
>>>[1, 2, 3, 4, 5, 6]
a = [1,2,3]
b = [4,5,6]
a.append(b)
print(a)
>>>[1, 2, 3, [4, 5, 6]]