append
添加一個單獨的元素到數組的末尾,數組長度增加1
my_list = ['geeks', 'for']
my_list.append('geeks')
print my_list
['geeks', 'for', 'geeks']
my_list = ['geeks', 'for', 'geeks']
another_list = [6, 0, 4, 1]
my_list.append(another_list)
print my_list
['geeks', 'for', 'geeks', [6, 0, 4, 1]]
extend
把添加的列表拆分開來,一個一個append到要添加的列表末尾
my_list = ['geeks', 'for']
another_list = [6, 0, 4, 1]
my_list.extend(another_list)
print my_list
['geeks', 'for', 6, 0, 4, 1]
my_list = ['geeks', 'for', 6, 0, 4, 1]
my_list.extend('geeks')
print my_list
['geeks', 'for', 6, 0, 4, 1, 'g', 'e', 'e', 'k', 's']