Python3 list.append()方法

append()方法附加一個傳遞的obj對象到現有的列表中。

語法

以下是 append()方法的語法 -
list.append(obj)

參數

  • obj -- 這是要追加在列表中的對象。

返回值

此方法不返回任何值,但更新現有的列表。

示例

下麵的示例演示 append()方法的使用。
#!/usr/bin/python3
list1 = ['C++', 'Java', 'Python']
list1.append('C#')
print ("updated list : ", list1)

當我們運行上面的程式,會產生以下結果 -
updated list :  ['C++', 'Java', 'Python', 'C#']

上一篇: Python3字串 下一篇: Python3列表