一、一般写法
num = 75
if num > 60 :
print('及格')
else:
print('不及格')
二、简单写法
num = 75
chengji = '及格' if num > 60 else '不及格'
print(chengji)
三、元组
num = 75
# 元组中(false , true),只有第一和第二
chengji = ('不及格','及格',)[num > 60]
print(chengji)
四、字典写法
num = 80
# false = 0 ; true = 1 只有0: 和1:
chengji = {0:'不及格',1:'及格',2:'优秀'}[num > 60]
print(chengji)
五、字典加强
num = 95
# false = 0 ; true = 1
chengji = {0:'不及格'}.get(num > 90,'优秀学生')
print(chengji)
六、进阶
num = 50
# false = 0 ; true = 1
chengji = (num > 60) and '及格' or '不及格'
print(chengji)