描述
- append()方法:用於向列表末尾添加新的對象。
語法
- 語法格式:
list.append(object)
參數
- object:添加到列表末尾的對象,這里的對象可以是一個元素、列表、字典或元組等。
返回值
- 無返回值
實例
實例:
#!/usr/bin/python3 a = ['abc', '2019_11', 'pople'] bac = ['aYuYa'] others = {'name': 'jack'} tuples = ('yxs', 100) a.append('python') a.append(bac) a.append(tuples) a.append(others) print("New list: " + str(a))
輸出:
New list: ['abc', '2019_11', 'pople', 'python', ['aYuYa'], ('yxs', 100), {'name': 'jack'}]