1、append:增加元素到列表尾部

L.append(object) -> None -- append object to end

2、clear:清空列表中所有元素

3、count:返回列表中指定值的数量

L.count(value) -> integer -- return number of occurrences of value

4、extend:用列表扩展列表的元素

#L.extend(iterable) -> None -- extend list by appending elements from the iterable
l1 = [1,2,3]
l2 = [3,4,5]
l1.extend(l2)
print(l1)

5、index:返回指定元素的索引位置

#L.index(value, [start, [stop]]) -> integer -- return first index of value
lx = ['today','is','a','good','day']
print(lx.index('is'))
结果:

6、insert:在指定索引位置插入

#L.insert(index, object) -- insert object before index
lx = ['today','is','a','good','day']
lx.insert(,'not')
print(lx)
结果:['today', 'is', 'not', 'a', 'good', 'day']

7、pop:删除列表指定位置的元素,默认为最后一个元素

#L.pop([index]) -> item -- remove and return item at index (default last)
lx = ['today','is','a','good','day']
lx.pop()
print(lx)
结果:['today', 'is', 'good', 'day']

8、remove:删除列表中指定的元素

#L.remove(value) -> None -- remove first occurrence of value
lx = ['today','is','a','good','day']
lx.remove('a')
print(lx)
结果:['today', 'is', 'good', 'day']

9、reverse:将列表中所有元素反转

#L.reverse() -- reverse *IN PLACE*
lx = ['today','is','a','good','day']
lx.reverse()
print(lx)
结果:['day', 'good', 'a', 'is', 'today']

10、sort:排序

#原址排序
x= [,,,,,,,]
x.sort()
print(x)
结果:[, , , , , , , ] #需要一个排序好的副本,通过切片方法将x赋值给y
x= [,,,,,,,]
y = x[:]
y.sort()
print(x)
print(y)
结果:
[, , , , , , , ]
[, , , , , , , ] #再一种通过sorted
x= [,,,,,,,]
y = sorted(x)
print(x)
print(y)
结果:
[, , , , , , , ]
[, , , , , , , ]

11、filter:使用一个自定义的涵数过滤一个序列,把函数的每一项传到自定义的函数里处理,最终一次性返回过滤的结果

def func(x):
if x >:
return True li = [,,,,]
new_list = filter(func,li)
print(list(new_list))
结果:[44,55]

12、zip:接受任意多个序列,返回一个元组

x = [,,]
y = [,,]
z = [,,]
zipped = zip(x,y,z)
yy = list(zipped)
xyz =zip(*yy) #zip的反函数
print(yy)
print(list(xyz))
结果:
[(, , ), (, , ), (, , )]
[(, , ), (, , ), (, , )]

13、tell:查看当前指针位置

  seek:定位当前指针位置

'''test.llog
孔kongzhagen
''' f = open('test.log','r+',encoding='utf-8')
f.read()
print(f.tell()) #查看当前指针位置 f.seek()
f.read()
print(f.tell())
结果:,

14、truncate: truncate(n):  从文件的首行首字符开始截断,截断文件为n个字符;无n表示从当前位置起截断;截断之后n后面的所有字符被删除。其中win下的换行代表2个字符大小。

'''
# Assuming file has following lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line
'''
f = open("test.log","r+")
print('Name of file %s'%f.name)
line = f.readline()
print('Read line:%s'%line)
f.truncate(f.tell()) #文件保留了第一行,其余被截断
line = f.readline()
print('Read line:%s'%line)
f.close()
结果:
Name of file test.log
Read line:# Assuming file has following lines Read line:# This is 1st line

其它

numList = [,,,,,]
strList = ['a','b','c','d','e']
numList.append() # numList列表增加一个值
print numList
print numList.count() # 列表中2出现的次数
numList.extend(strList) # strList的内容增加到numList后面
print numList
print numList.index() # numList中23的索引位置
numList.insert(,) # 在numList的3索引位置添加45
print numList
print numList.pop() # 获取并删除numList最后一个值
numList.remove() # 从numList中删除4
print numList
numList.reverse() # 获取numList的反向列表
print numList

python数据类型之list的更多相关文章

  1. python 数据类型---布尔型& 字符串

    python数据类型-----布尔型 真或假=>1或0 >>> 1==True True >>> 0==False True python 数据类型----- ...

  2. Python 数据类型及其用法

    本文总结一下Python中用到的各种数据类型,以及如何使用可以使得我们的代码变得简洁. 基本结构 我们首先要看的是几乎任何语言都具有的数据类型,包括字符串.整型.浮点型以及布尔类型.这些基本数据类型组 ...

  3. day01-day04总结- Python 数据类型及其用法

    Python 数据类型及其用法: 本文总结一下Python中用到的各种数据类型,以及如何使用可以使得我们的代码变得简洁. 基本结构 我们首先要看的是几乎任何语言都具有的数据类型,包括字符串.整型.浮点 ...

  4. Python数据类型及其方法详解

    Python数据类型及其方法详解 我们在学习编程语言的时候,都会遇到数据类型,这种看着很基础也不显眼的东西,却是很重要,本文介绍了python的数据类型,并就每种数据类型的方法作出了详细的描述,可供知 ...

  5. Python学习笔记(五)--Python数据类型-数字及字符串

    Python数据类型:123和'123'一样吗?>>> 123=='123'False>>> type(123)<type 'int'>>> ...

  6. python数据类型之元组、字典、集合

    python数据类型元组.字典.集合 元组 python的元组与列表类似,不同的是元组是不可变的数据类型.元组使用小括号,列表使用方括号.当元组里只有一个元素是必须要加逗号: >>> ...

  7. 1 Python数据类型--

    常见的Python数据类型: (1)数值类型:就是平时处理的数字(整数.浮点数) (2)序列类型:有一系列的对象并排或者排列的情况.如字符串(str),列表(list),元组(tuple)等 (3)集 ...

  8. Python数据类型和数据操作

    python数据类型有:int,float,string,boolean类型.其中string类型是不可变变量,用string定义的变量称为不可变变量,该变量的值不能修改. 下面介绍python中的l ...

  9. Python数据类型(python3)

    Python数据类型(python3) 基础数据类型 整型 <class 'int'> 带符号的,根据机器字长32位和64位表示的范围不相同,分别是: -2^31 - 2^31-1 和 - ...

  10. 二、Python数据类型(一)

    一.Python的基本输入与输出语句 (一)输出语句 print() 示例: print('你好,Python') print(4+5) a = 10 print(a) 输出的内容可以是字符串,变量, ...

随机推荐

  1. Google protobuf

    个人理解: 定义.proto文件就是指明消息里包含的成员和类型,protoc会compile成相应的java文件包含interface和implementation class,然后在构建messag ...

  2. linux命令:ls

    1.介绍: ls是linux日常操作中用的最多命令,是list的缩写,默认按名称排序列出当前目录和文件,ls --help可以查看帮助. 2.命令格式: ls [OPTION] [FILE] 3.命令 ...

  3. 学习笔记:js、css、html判断浏览器的各种版本

    js.css.html判断浏览器的各种版本 (转载自:http://www.jb51.net/web/42244.html  版权归原作者所有) 利用正则表达式来判断ie浏览器版本 判断是否IE浏览器 ...

  4. Euro Efficiency_完全背包

    Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...

  5. Nearest number - 2_暴力&&bfs

    Description Input is the matrix A of N by N non-negative integers. A distance between two elements A ...

  6. iOS-申请开发证书流程

    1.开发者证书(分为开发和发布两种,类型为ios Development,ios Distribution),这个是最基础的,不论是真机调试,还是上传到appstore都是需要的,是一个基证书,用来证 ...

  7. Android FM模块学习之一 FM启动流程

    最近在学习FM模块,FM是一个值得学习的模块,可以从上层看到底层. 上层就是FM的按扭操作和界面显示,从而调用到FM底层驱动来实现广播收听的功能. FM启动流程:如下图: 先进入FMRadio.jav ...

  8. windows操作系统的快捷键

    编号:1015时间:2016年5月26日09:25:34功能:windows操作系统的快捷键URL:https://www.douban.com/group/topic/5937774/

  9. 蓝牙SIG

    蓝牙SIG 蓝牙SIG是一个国际性的非营利组织,它的目的是制定蓝牙的技术规范和推广蓝牙技术的应用.该组织由发起会员(Promoter).合作会员(Associate Member)和接受会员(Adop ...

  10. 接口变化统计工具--Clirr

    最近学习Mybatis的官方文档,看到了[项目文档]一节有很多内容没有见过,做个笔记,理解一下. 当写一个公共库,或者SDK,版本与版本之间迭代之后,总会发生接口的变化,而这些变化,都需要向外界进行告 ...