python列表操作。
2013-05-13 18:02
197 查看
通过索引操作列表:
通过索引操作列表:
给列表增加一个元素 .append
.pop .remove del用法:
n = [1, 3, 5] # Add your code below s = n[1] print s 这里n中有三个元素,索引是从0开始计算。实例中的1代表的从0开始。
通过索引操作列表:
n = [1, 3, 5] # Do your multiplication here print n n[1] = n[1] * 5 print n ----------------------------------------------- 另外一种写法。 n = [1, 3, 5] # Do your multiplication here print n n[1] *= 5 print n
给列表增加一个元素 .append
n = [1, 3, 5] # Append the number 4 here n.append(4) print n
.pop .remove del用法:
n = [1, 3, 5] # Remove the first item in the list here n.pop(0) print n 这里的0代表索引。
n = [1, 3, 5] # Remove the first item in the list here n.remove(1) print n 这里的一代表的是元素。
n = [1, 3, 5] # Remove the first item in the list here del (n[0]) print n 这里的0代表的索引。
相关文章推荐
- python 列表操作 及 使用方法
- Python列表操作——模拟实现栈和队列
- 04-python的列表操作
- (转载)Python 列表(list)操作
- Python入门(02) -- 列表操作
- Python 列表操作
- Python+Selenium 操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表
- Python redis 列表的取出,插入操作
- Python 列表(list)操作
- python实操(5):python数据类型及常用操作,数字、字符串、元组、列表、字典、集合
- Python中字符串、列表的基本操作
- 菜鸟的Python之路--基础知识(列表的基本操作)
- Python 列表的操作
- python3 -- 列表操作 -深拷贝、浅拷贝、遍历
- Python基础二之简单列表操作补充
- python 列表常用操作(二)
- python中列表和元组以及字符串的操作
- Python针对给定列表中元素进行翻转操作的方法分析
- Python对于列表的del, remove, pop操作的区别
- Python----字符串操作与列表使用