當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python List append方法用法及代碼示例

Python 的 list.append(~) 方法將一個項目添加到列表的末尾。

參數

1.x | any type

要添加到列表末尾的項目。

返回值

None

例子

基本用法

要將 'green' 添加到列表 colors 的末尾:

colors = ['red', 'blue']
colors.append('green')
print(colors)



['red', 'blue', 'green']

相關用法


注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Python List | append method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。