Python3.x:python: extend (擴展) 與 append (追加) 的區別
1,區別:
append() 方法向列表的尾部添加一個新的元素。只接受一個參數;
extend()方法只接受一個列表作為參數,並將該參數的每個元素都添加到原有的列表中;
2,示例:
list_extend = ['a', 'b', 'c'] list_extend.extend(['d', 'e', 'f']) print("list_extend:%s" %list_extend) # 輸出結果:list_extend:['a', 'b', 'c', 'd', 'e', 'f'] list_append = ['a', 'b', 'c'] list_append.append(['d', 'e', 'f']) print("list_append:%s" %list_append) # 輸出結果:list_append:['a', 'b', 'c', ['d', 'e', 'f']]
作者:整合俠
鏈接:http://www.cnblogs.com/lizm166/p/8232733.html
來源:博客園
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。