版权声明:本文为博主原创文章,转载请注明出处。 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')
elif
是else if
的缩写
if
判断条件还可以简写,比如写:
if x:
print('True')
只要x
是非零数值、非空字符串、非空list等,就判断为True
,否则为False
。