list 列表遍历
来源:互联网 发布:mac玩游戏时dock栏 编辑:程序博客网 时间:2024/05/29 23:22
list=["apple","banana","grape","orange"]
print list
print list[2]
list.append("watermelon") #末尾附加元素
list.insert(1,"grapefruit") #插入第二个位置元素
print list
list.remove("grape") #移除元素
print list
#list.remove("a")
print list.pop(2) #弹出第三位元素,并移出列表
print list
list=["apple","banana","grape","orange"]
print list[-2]
print list[1:3]
print list[-3:-1]
list=[["apple","banana"],["grape","orange"],["watermelon"],["grapefruit"]]
for i in range(len(list)):
print "list[%d]:"%i,"",
for j in range(len(list[i])):
print list[i][j],"",
print list
print list[2]
list.append("watermelon") #末尾附加元素
list.insert(1,"grapefruit") #插入第二个位置元素
print list
list.remove("grape") #移除元素
print list
#list.remove("a")
print list.pop(2) #弹出第三位元素,并移出列表
print list
list=["apple","banana","grape","orange"]
print list[-2]
print list[1:3]
print list[-3:-1]
list=[["apple","banana"],["grape","orange"],["watermelon"],["grapefruit"]]
for i in range(len(list)):
print "list[%d]:"%i,"",
for j in range(len(list[i])):
print list[i][j],"",
print #空格行
======================= RESTART: C:/Python27/list1.py =======================
['apple', 'banana', 'grape', 'orange']
grape
['apple', 'grapefruit', 'banana', 'grape', 'orange', 'watermelon']
['apple', 'grapefruit', 'banana', 'orange', 'watermelon']
banana
['apple', 'grapefruit', 'orange', 'watermelon']
grape
['banana', 'grape']
['banana', 'grape']
list[0]: apple banana
list[1]: grape orange
list[2]: watermelon
list[3]: grapefruit
阅读全文
0 0
- Java遍历List列表
- list 列表遍历
- 遍历List列表进行选择性的删除操作
- List遍历
- list遍历
- list遍历
- List遍历
- 列表(List)
- 列表list
- 列表List
- 列表 list
- 列表list
- python学习笔记--打印嵌套list中每个数据(遍历列表)
- <c:foreach>解决遍历一个list创建多行多列列表的问题
- python的【列表list】:定义、索引、添加、删除、遍历、长度;组合、重复、反转、切片、比较;排序
- 【C#】遍历List列表的同时,移除访问到的元素
- 在js中如何遍历List集合,并且动态渲染下拉列表数据
- Python遍历列表的方法enumerate,以及清空list方法
- A1006
- EJB注解详细说明
- 硬件测试工程师系列0--写在最开始
- 如何看待职业倦怠
- 网卡绑定7种模式
- list 列表遍历
- Genymotion模拟器出现Unable to create virtual device Fail to create SD card错误的解决
- 水题(Water problem,HDU 5867)
- 0、Python 算法分析
- JAVA并发编程实践 中英文ebook
- 绝对最大额定值(ABSOLUTE MAXIMUM RATINGS: ABS)是否可以超过
- EJB注解详细说明1
- vim/vi命令全解
- nyoj-27 水池数目