标签:运算符 map list pre lte xiaomi lis == rgs
# a = 1
# result = ‘xiaoming‘ if a == 1 else ‘xiaohuang‘
# print(result)
#
# def func(arg):
# return arg + 1
# print(func(3))
# a = lambda arg:arg+1
#
# print(a(8))
#
# func = lambda *args : print(args)
#
# print(func(2,3,4))
# map
# li = [1,2,3,4,5]
# def func(s):
# # return s+1
# # ret = map(func,li)
# # print(ret)
# # print(next(ret))
# # print(list(ret))
# print(list(map(lambda li : li + 1,li)))
# filter
# li = [22,33,44,55]
#
# def func(huang):
# if huang > 33:
# return huang
# ret = filter(func,li)
# print(list(ret))
#
# print(list(filter(lambda huang : huang >33,li)))
# reduce
from functools import reduce
li = [1,2,3,4]
def func(a,b):
return a+b
ret = reduce(func,li)
print(ret)
li2 = [22,33,44]
print(reduce(lambda a,b : a+b,li2))
标签:运算符 map list pre lte xiaomi lis == rgs
原文地址:https://www.cnblogs.com/huangjiangyong/p/10549870.html