我是靠谱客的博主 从容金鱼,这篇文章主要介绍Python3.x:python: extend (扩展) 与 append (追加) 的区别Python3.x:python: extend (扩展) 与 append (追加) 的区别,现在分享给大家,希望可以做个参考。
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
来源:博客园
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
转载于:https://www.cnblogs.com/lizm166/p/8232733.html
最后
以上就是从容金鱼最近收集整理的关于Python3.x:python: extend (扩展) 与 append (追加) 的区别Python3.x:python: extend (扩展) 与 append (追加) 的区别的全部内容,更多相关Python3.x:python:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复