码迷,mamicode.com
首页 > 其他好文 > 详细

三元运算符

时间:2019-03-18 01:08:03      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:运算符   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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!