新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonappend()
python 中的append()函數(shù)有助于將給定的項目添加到現(xiàn)有列表的末尾。

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名申請、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、岱岳網(wǎng)站維護、網(wǎng)站推廣。
**list.append(item)** #where item can be numbers, strings, dictionaries etc
追加()參數(shù):
append()函數(shù)接受一個參數(shù)。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 項目 | 要添加到列表末尾的項目 | 需要 |
追加()返回值
這個方法不返回任何值,這意味著它不返回任何值。實際上,這個方法更新了現(xiàn)有的列表。
Python 中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'] 示例 2:如何使用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']] 文章題目:創(chuàng)新互聯(lián)Python教程:Pythonappend()
瀏覽地址:http://m.5511xx.com/article/coeeoce.html


咨詢
建站咨詢
