s=[1,2,3,4]
s.append(5,6,7)
print(s)
为什么没有成功?该怎么办?
代码改成这样:
s=[1,2,3,4]
s.append(5)
s.append(6)
s.append(7)
print(s)
输出:
>>>
[1, 2, 3, 4, 5, 6, 7]
>>>
append()里面只能一个参数,如果你要直接追加5,6,7,就得用extend()函数,示例如下:
res = [3,4,5]
res.extend([6,7,8])
print(res)
[3, 4, 5, 6, 7, 8]
append一次只能添加一个参数,分成三次就行了