#a list
cars = 'Ford', 'Volvo', 'BMW', 'Tesla'
#append item to list
cars.append('Audi')
print(cars)
list = 'Hello', 1, '@'
list.append(2)
list
'Hello', 1, '@', 2
list = 'Hello', 1, '@', 2
list.append((3, 4))
list
'Hello', 1, '@', 2, (3, 4)
list.append(3, 4)
list
['Hello', 1, '@', 2, (3, 4), 3, 4]
list.append(3, 4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: append() takes exactly one argument (2 given)
list.extend(5, 6)
list
['Hello', 1, '@', 2, (3, 4), 3, 4, 5, 6]
list.extend((5, 6))
list
['Hello', 1, '@', 2, (3, 4), 3, 4, 5, 6, 5, 6]
list.extend(5, 6)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: extend() takes exactly one argument (2 given)
Reference:
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。