python: append & extend 异同
来源:互联网 发布:快刀抢票软件 编辑:程序博客网 时间:2024/05/17 02:15
经过试验,总结出 python 中 append 和 extend 的异同点如下表:
代码示例0:
list = ('Hello', 1, '@')list
('Hello', 1, '@')
list.append('#')
Traceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'tuple' object has no attribute 'append'
list.extend('#')
Traceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'tuple' object has no attribute 'extend'
AttributeError: ‘tuple’ object has no attribute ‘append’、 ‘extend’:说明append、 extend只能作用于 list 型数据。
代码示例1:
list = ['Hello', 1, '@']list.append(2)list
['Hello', 1, '@', 2, 3]
list = ['Hello', 1, '@', 2]list.append((3, 4))list
['Hello', 1, '@', 2, (3, 4)]
list.append([3, 4])list
['Hello', 1, '@', 2, (3, 4), [3, 4]]
list.append(3, 4)
Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: append() takes exactly one argument (2 given)
list.extend([5, 6])list
['Hello', 1, '@', 2, (3, 4), [3, 4], 5, 6]
list.extend((5, 6))list
['Hello', 1, '@', 2, (3, 4), [3, 4], 5, 6, 5, 6]
list.extend(5, 6)
Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: extend() takes exactly one argument (2 given)
TypeError: append() takes exactly one argument、TypeError: extend() takes exactly one argument:说明append、 extend每次只能输入单参数。
阅读全文
1 0
- python: append & extend 异同
- python list.append 和 list.extend() 的功能及异同
- python extend append
- python extend append
- python extend() append()
- python: extend(),append(),insert()
- python 的 append 和 extend
- python List append() vs. extend()
- Python的extend()和append()
- python extend和append总结
- python | append( ) & extend( )的区别
- python 中 append 与 extend
- python中的append与extend
- python .extend() and append()函数
- Python-append和extend函数
- python 笔记 for loop and extend, append
- python中的extend和append的区别
- Python List中append()与extend()
- easyui树形结构读取菜单
- PBOC规范研究之六、变长记录文件(转)
- Unity插件菜单
- iOS 从0到1搭建高可用App框架
- Linux进程与线程概述
- python: append & extend 异同
- 二叉树
- 亚洲诚信:钓鱼网站飙升居然因为浏览器...
- Android多线程篇(下)-安卓基础知识整理
- Swift3.0基础之详细讲解Closure闭包结构的使用
- Myeclipse2016 安装与破解
- 观察者模式
- Mat
- 无法访问中文维基百科