2019-03-30
阅读量:
402
区分元组,字典和lambda的用法
使用元组,字典和lambda的直接方法
# Python program to demonstrate ternary operator
a, b = 10, 20
# Use tuple for selecting an item
print( (b, a) [a < b] )
# Use Dictionary for selecting an item
print({True: a, False: b} [a < b])
# lamda is more efficient than above two methods
# because in lambda we are assure that
# only one expression will be evaluated unlike in
# tuple and Dictionary
print((lambda: b, lambda: a)[a < b]())
输出:
10
10
10






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论