前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >6种方法使用python append

6种方法使用python append

作者头像
用户8418197
发布2022-03-05 20:58:46
1.1K0
发布2022-03-05 20:58:46
举报
文章被收录于专栏:howtouselinuxhowtouselinux

Example 1

#a list

cars = 'Ford', 'Volvo', 'BMW', 'Tesla'

#append item to list

cars.append('Audi')

print(cars)

Example 2

list = 'Hello', 1, '@'

list.append(2)

list

'Hello', 1, '@', 2

Example 3

list = 'Hello', 1, '@', 2

list.append((3, 4))

list

'Hello', 1, '@', 2, (3, 4)

Example 4

list.append(3, 4)

list

['Hello', 1, '@', 2, (3, 4), 3, 4]

Example 5

list.append(3, 4)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: append() takes exactly one argument (2 given)

Example 6

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:

how to append list in python

how to add items to a list in python

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
目录
  • Example 1
  • Example 2
  • Example 3
  • Example 4
  • Example 5
  • Example 6
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档