三元运算符
Posted huangjiangyong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三元运算符相关的知识,希望对你有一定的参考价值。
# 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))
以上是关于三元运算符的主要内容,如果未能解决你的问题,请参考以下文章