python list 操作 增删查
2014-08-15 07:29
393 查看
List查询数组里面的元素直接 数组名称.[数组序号]就可以了 例如数组b, b[2] <span style="font-size:18px;"><strong>增加元素有3种方式</strong></span> 1.append() 增加在最后面 例如 <pre name="code" class="python">b.append('world')
2.insert()可以进行选择插入到第几个
例如:
>>> b.insert(0,'xiao')3.extend() 增加多个元素
例如
>>> b.extend(['by','pragram'])删除元素有3种方式
remove() 直接移除list中的字符串
例如
b.remove('xiao')
del 直接移除list序号的字符串
例如
del b[2]
pop()
例如
b.pop(2)默认是最后一个
>>> b=['change','the'] >>> b.append('world') >>> b['change', 'the', 'world'] >>> b.extend(['by','pragram']) >>> b['change', 'the', 'world', 'by', 'pragram'] >>> b.insert(0,'xiao') >>> b['xiao', 'change', 'the', 'world', 'by', 'pragram'] >>> b[2]'the' >>> b.remove('xiao') >>> b['change', 'the', 'world', 'by', 'pragram'] >>> del b(1)SyntaxError: can't delete function call >>> del b[1] >>> b['change', 'world', 'by', 'pragram'] >>> a=b; >>> b.pop()'pragram' >>> b['change', 'world', 'by'] >>> name=b.pop() >>> name'by' >>> name=b.pop(1) >>> name'world' >>> b['change'] >>>
相关文章推荐
- python中的list如何进行相减操作或者将list分片
- Python 列表 list 数组 array 常用操作集锦
- python的list操作
- [python小菜]内建数据类型list 利用切片添加操作
- python list操作 - 转
- python整理八——list的简单操作
- Python 中list, dictionary 与 file相互操作
- Python 列表 list 数组 array 常用操作集锦
- Python中的基本list操作
- (转载)Python 列表(list)操作
- python list的+=操作
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- Python list 操作
- Python list 操作
- Python 区分List和一维数组的不同操作
- python中的list如何进行相减操作或者将list分片
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- python中list操作
- python的list操作
- Python 中list, dictionary 与 file相互操作