Python第七课 条件判断

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/sinat_27305053/article/details/88891426
age = 3
if age >= 18:
    print('your age is', age)
    print('adult')
else:
    print('your age is', age)
    print('teenager')

注意不要少写了冒号:

age = 3
if age >= 18:
    print('adult')
elif age >= 6:
    print('teenager')
else:
    print('kid')

elifelse if的缩写

if判断条件还可以简写,比如写:

if x:
    print('True')

只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False

猜你喜欢

转载自blog.csdn.net/sinat_27305053/article/details/88891426