[i for i in range(10) if i>10]
23. 元组: x = 1, x = 1,2,3
24.x = (1,2,3,4)
2,3 之间插入 5
x[:2] + ('5',) + x[2:]
25.python 内置方法:
divmod(10,2) 返回 10 对 2 的除法和余数
pow(x,y,z) x 的 y 次方, 如果 z 存在, 则 %z
float,int,long,list,tuple,str,dict 转换为其类型
round 四舍五入 sum 求和
isinstance(1,int) 前者是否属于后者类型
'I am {0} ,I like {1}'.format('xy','d')
enumerate, 返回一个可枚举的对象 (tuple)
set
sorted 排序
all(集合) 集合中所有的元素都为真才为真
any(集合) 集合中有一个元素都为真才为真
cmp(x,y) x<y 返回负数 x==y 返回 0 x>y 返回正数
next() 返回迭代对象中的下一个元素
reversed(range(10)) 逆置对象
sorted() 对对象进行排序, 返回一个新的列表
zip 返回元组型
- x = [1,2,3]
- y = [4,5,6,7]
- print(list(zip(x,y))) [(1, 4), (2, 5), (3, 6)]
- map: list1 = map(lambda x:x**2,[1,2,3,4,5])
第一个是处理条件, 第二个是序列
返回值是 Object
filter: list1 = list(filter(lambda x:x%3 == 0,range(100)))
filter 第一个参数是过滤条件, 第二个是要过滤的内容
返回值是个 Object, 得转换为其他类型
help() 返回对象的帮助信息
input 读取用户输入的信息
open 打开文件
exec 执行动态语句块 exec('a=1+2')
来源: http://www.bubuko.com/infodetail-2569383.html