python列表操作——增

append:追加一条数据到列表的最后

name = ["Zhangsan","XiongDa","Lisi"]
name.append("wangwu")
print name
输出结果:
['Zhangsan', 'XiongDa', 'Lisi', 'wangwu']

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

insert:指定位置插入一条数据

name = ["Zhangsan","XiongDa","Lisi"]
name.insert(1,"wangwu")    #在下标为1的位置插入一条数据“wangwu”
print name
输出结果:
['Zhangsan', 'wangwu', 'XiongDa', 'Lisi']

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

python列表操作——删

name = ["Zhangsan","XiongDa","Lisi"]
name.remove("Lisi")    #删除指定的数据
print name
输出结果:
['Zhangsan', 'XiongDa']
name = ["Zhangsan","XiongDa","Lisi"]
del name[0]    #删掉下标为0的一条数据
print name
输出结果:
['XiongDa', 'Lisi']
name = ["Zhangsan","XiongDa","Lisi"]
name.pop()    #删除最后一条数据
print name
输出结果:
['Zhangsan', 'XiongDa']

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

如果当pop()中带入了参数,其效果等同于del

Name.pop(1) == del name[1]

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

python列表操作——改

name = ["Zhangsan","XiongDa","Lisi"]
name[1] = "wangwu"
print name
输出结果:
['Zhangsan', 'wangwu', 'Lisi']

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

python列表操作——查

name = ["Zhangsan","XiongDa","Lisi","wangwu"]
print(name[1])     #直接取出下标为1的数据
输出结果:
XiongDa
name = ["Zhangsan","XiongDa","Lisi","wangwu"]
print(name[0:2])   #取出从下标0到下标1的数据,不包括2(顾头不顾尾)
输出结果:
['Zhangsan', 'XiongDa']

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

当下标为负数时,则从右边开始取

name = ["Zhangsan","XiongDa","Lisi","wangwu"]
print(name[-1])     #直接取出下标为1的数据
输出结果:
wangwu
name = ["Zhangsan","XiongDa","Lisi","wangwu"]
print(name[-3:-1])   #从倒数第三个开始取,取到倒数第二个,因为不包括-1
输出结果:
['XiongDa', 'Lisi']
name = ["Zhangsan","XiongDa","Lisi","wangwu"]
print(name[-3:])   #从倒数第三个开始取,取到倒数第一个
输出结果:
['XiongDa', 'Lisi', 'wangwu']
同理从昨天开始取时
name[0:3] == name[:3]

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

列表其他操作:

name = ["Zhangsan","XiongDa","Lisi","wangwu","Lisi"]
name.count("Lisi")  #统计Lisi出现的次数
name.clear()         #清空数据
name.reverse()       #反转列表
name.sort()           正向排序
name2 = ["]
name.extend(name2)  #两个数组合并,name2放在后面

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

python列表操作——增

append:追加一条数据到列表的最后

name = ["Zhangsan","XiongDa","Lisi"]

name.append("wangwu")

print name

输出结果:

['Zhangsan', 'XiongDa', 'Lisi', 'wangwu']

insert:指定位置插入一条数据

name = ["Zhangsan","XiongDa","Lisi"]

name.insert(1,"wangwu")    #在下标为1的位置插入一条数据“wangwu

print name

输出结果:

['Zhangsan', 'wangwu', 'XiongDa', 'Lisi']

python列表操作——删

name = ["Zhangsan","XiongDa","Lisi"]

name.remove("Lisi")    #删除指定的数据

print name

输出结果:

['Zhangsan', 'XiongDa']

name = ["Zhangsan","XiongDa","Lisi"]

del name[0]    #删掉下标为0的一条数据

print name

输出结果:

['XiongDa', 'Lisi']

name = ["Zhangsan","XiongDa","Lisi"]

name.pop()    #删除最后一条数据

print name

输出结果:

['Zhangsan', 'XiongDa']

如果当pop()中带入了参数,其效果等同于del

Name.pop(1) == del name[1]

python列表操作——改

name = ["Zhangsan","XiongDa","Lisi"]

name[1] = "wangwu"

print name

输出结果:

['Zhangsan', 'wangwu', 'Lisi']

python列表操作——查

name = ["Zhangsan","XiongDa","Lisi","wangwu"]

print(name[1])     #直接取出下标为1的数据

输出结果:

XiongDa

name = ["Zhangsan","XiongDa","Lisi","wangwu"]

print(name[0:2])   #取出从下标0到下标1的数据,不包括2(顾头不顾尾)

输出结果:

['Zhangsan', 'XiongDa']

当下标为负数时,则从右边开始取

name = ["Zhangsan","XiongDa","Lisi","wangwu"]

print(name[-1])     #直接取出下标为1的数据

输出结果:

wangwu

name = ["Zhangsan","XiongDa","Lisi","wangwu"]

print(name[-3:-1])   #从倒数第三个开始取,取到倒数第二个,因为不包括-1

输出结果:

['XiongDa', 'Lisi']

name = ["Zhangsan","XiongDa","Lisi","wangwu"]

print(name[-3:])   #从倒数第三个开始取,取到倒数第一个

输出结果:

['XiongDa', 'Lisi', 'wangwu']

同理从昨天开始取时

name[0:3] == name[:3]

列表其他操作:

name = ["Zhangsan","XiongDa","Lisi","wangwu","Lisi"]

name.count("Lisi")  #统计Lisi出现的次数

name.clear()         #清空数据

name.reverse()       #反转列表

name.sort()           正向排序

name2 = ["1","2"]

name.extend(name2)  #两个数组合并,name2放在后面

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
table.MsoTableGrid
{mso-style-name:网格型;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
font-family:宋体;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}

python学习笔记——列表操作的更多相关文章

  1. python学习笔记:文件操作和集合(转)

    转自:http://www.nnzhp.cn/article/16/ 这篇博客来说一下python对文件的操作. 对文件的操作分三步: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句 ...

  2. python学习笔记——列表生成式与生成器

    1.列表生成式(List Comprehensions) python中,列表生成式是用来创建列表的,相较于用循环实现更为简洁.举个例子,生成[1*1, 2*2, ... , 10*10],循环用三行 ...

  3. Python学习笔记----列表、元组和字典的基础操作

    文章目录 一.列表的基本操作 1.1 修改列表中的某个数据 1.2 获取某个元素的返回值(返回的是索引) 1.3 在列表中插入新的元素 1.4 删除列表中的元素 1.5 +和* 二.内置的函数和方法 ...

  4. python 学习笔记 redis操作

    Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorte ...

  5. Python学习笔记——文件操作

    python中,一切皆对象.   一.文件操作流程 (1)打开文件,得到一个文件句柄(对象),赋给一个对象: (2)通过文件句柄对文件进行操作: (3)关闭文件. 文件对象f通过open()函数来创建 ...

  6. python学习笔记之——操作mysql数据库

    Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库,你可以选择适合你项目的数据库: ...

  7. Python学习笔记——列表

    1.创建列表类型数据并给其赋值 >>> aList = [123,'abc',4.56,['inner','list'],7-9j] >>> aList [123, ...

  8. Python学习笔记_操作Excel

    Python 操作Exel,涉及下面几个库: 1.xlrd 读取Excel文件 2.xlwt 向Excel文件写入,并设置格式 3.xlutils 一组Excel高级操作工具,需要先安装xlrd和xl ...

  9. 03 python学习笔记-文件操作(三)

    本文内容主要包括以下方面: 1. 文件操作基本认识2. 只读(r, rb)3. 只写(w, wb)4. 追加(a, ab)5. r+读写6. w+写读7. a+写读(追加写读)8. 文件的修改 一.文 ...

随机推荐

  1. javaWeb学习总结(8)- JSP标签(6)

    一.JSP标签介绍 JSP标签也称之为Jsp Action(JSP动作)元素,它用于在Jsp页面中提供业务逻辑功能,避免在JSP页面中直接编写java代码,造成jsp页面难以维护. 二.JSP常用标签 ...

  2. 关于RFID2.4G 标签卡最新方案

    它是一款针对RFID有源卡行业设计的,是一款单向的2.4G频段RF射频芯片,目前主要针对低功耗的校讯通, 2.4G停车场,电动车防盗, 闪光灯设备(引闪器) ,智能家居等领域.SI24R2E 同样与S ...

  3. 实现分布式队列ZooKeeper的实现

    一.背景 有一些时候,多个团队需要共同完成一个任务,比如,A团队将Hadoop集群计算的结果交给B团队继续计算,B完成了自己任务再交给C团队继续做.这就有点像业务系统的工作流一样,一环一环地传下去,直 ...

  4. AngularJS入门第一课

    1.ng-app=" "   定义angularJS的使用范围: 2.ng-init="变量=值;变量='值'"   初始化变量的值,有多个变量时,中间用分号隔 ...

  5. 【2017-06-01】Linq基础+Lambda表达式实现对数据库的增删改查

    一.Linq to sql 类 高集成化的数据库访问技术 使用Linq可以代替之前的Ado.Net.省去了自己敲代码的实体类和数据访问类的大量工作. 实体类: 添加一个Linq to sql 类 -- ...

  6. Qt之新手打包发布程序

    工具:电脑必备.QT下的windeployqt Qt 官方开发环境使用的动态链接库方式,在发布生成的exe程序时,需要复制一大堆 dll,如果自己去复制dll,很可能丢三落四,导致exe在别的电脑里无 ...

  7. FTP主动模式和被动模式的区别

    基础知识: FTP只通过TCP连接,没有用于FTP的UDP组件.FTP不同于其他服务的是它使用了两个端口, 一个数据端口和一个命令端口(或称为控制端口).通常21端口是命令端口,20端口是数据端口.当 ...

  8. JavaScript 特效三大系列总结

    一. offset系列 1. offset系列的5个属性 1. offsetLeft : 用于获取元素到最近的定位父盒子的左侧距离 * 计算方式: 当前元素的左边框的左侧到定位父盒子的左边框右侧 * ...

  9. 安装Mysql5.7并修改初始密码

    Centos 安装MySQL可以参考之前写的一篇文章 Centos7.3 安装Mysql5.7并修改初始密码 windows安装mysql5.7有两种方式 1.下载.msi安装文件直接根据界面提示进行 ...

  10. sleep()方法和wait()方法之间有什么差异?

    sleep()方法用被用于让程序暂停指定的时间,而wait()方法被调用后,线程不会自动苏醒,需要别的线程调用同一个对象上的notify()或者nofifyAl()方法 主要的区别是,wait()释放 ...