您的位置:首页 > 编程语言 > Python开发

Python之Lambda表达式和if not...else用法

2017-12-06 11:18 1876 查看
# -*- coding: utf-8 -*-

print("*******if...else语句*********")
#if 条件为真的时候返回if前面内容,否则返回0
exp1= lambda x:x+1 if  2==1 else 0
print(exp1(2))

exp2 = lambda x:x+1 if  1==1 else 0
print(exp2(2))

print("*******if not...else语句*********")
#if not 为假返回if not前面内容,否则返回0
exp3 = lambda x:x+1 if not 2==1 else 0
print(exp3(2))

exp4 = lambda x:x+1 if not 1==1 else 0
print(exp4(2))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python lambda