内置函数

zip   拉链函数 zip(iter1,iter2)

map 映射函数 map(function,iter1)   将可迭代对象通过函数一一带入

filtter 过滤函数 filtter(function,iter)  将可迭代对象通过function进行数据过滤

reduce 累计算

enumerate 枚举

lambda 匿名函数  lambda 参数:返回值

列表推导式  [结果  for循环  条件]

# 1 zip函数
lst1 = [1,2,3]
lst2 = ["a","b","c","d"]
print(list(zip(lst1,lst2)))
# 运行结果:[(1, 'a'), (2, 'b'), (3, 'c')]
# 2 map函数
print(list(map(lambda x:x**x,lst1)))
# 运行结果:[1, 4, 27]
# 3 filtter函数
print(list(filter(lambda x:x>1,lst1)))
# 运行结果:[2, 3]
# 4 reduce 函数
from functools import reduce
print(reduce(lambda x,y:x+y,lst1))
# 运行结果:6
# 5 匿名函数
print((lambda x:x+1)(10))
# 运行结果:11
# 6 列表推导式
print([i for i in range(20) if i>10])
# 运行结果:[11, 12, 13, 14, 15, 16, 17, 18, 19]
# 7 enumerate
lst = ["登录","查余额","转账金额"]
for k ,v in enumerate(lst,1):
    print(k,v,end=' ')
# 运行结果:1 登录 2 查余额 3 转账金额 

 

posted on 2019-02-15 16:11  Shawn_1026  阅读(121)  评论(0编辑  收藏  举报