python3(五) if

mac2022-06-30  19

age = 20 if age >= 18: print('your age is', age) print('adult') # 如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做。 # else else: age = 3 if age >= 18: print('your age is', age) print('adult') else: print('your age is', age) print('teenager') print('hello') # if elif else age = 3 if age >= 18: print('adult') elif age >= 6: print('teenager') else: print('kid') # 只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False。 x = 5 if x: print('True') # input 默认返回的是 str 不能喝整数做比较 # birth = input('birth: ') # if birth < 2000: # print('00前') # else: # print('00后') # 修改如下 s = input('birth: ') birth = int(s) if birth < 2000: print('00前') else: print('00后')

 

转载于:https://www.cnblogs.com/shaozhiqi/p/11543485.html

最新回复(0)