python 中的append()函数有助于将给定的项目添加到现有列表的末尾。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请、虚拟空间、营销软件、网站建设、岱岳网站维护、网站推广。
**list.append(item)** #where item can be numbers, strings, dictionaries etc
append()函数接受一个参数。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 项目 | 要添加到列表末尾的项目 | 需要 |
这个方法不返回任何值,这意味着它不返回任何值。实际上,这个方法更新了现有的列表。
append()方法的示例append()在 python 中是如何工作的? # flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']
# 'Sunflower' is appended to the flowers list
flowers.append('Sunflower')
# Updated flowers list
print('Updated flowers list: ', flowers )
输出:
Updated flowers list: ['Rose', 'Lotus', 'Jasmine', 'Sunflower'] append()向列表中添加列表 # flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']
# flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']
# list of vegetables
vegetables = ['Tomato', 'Potato']
# appending vegetables list to the flowers list
flowers.append(vegetables)
print('Updated list: ', flowers)
输出:
Updated list: ['Rose', 'Lotus', 'Jasmine', ['Tomato', 'Potato']]