Python if 语句
认识:
Python 的 if 语句是一个判断语句,如果对应的表达值的值非 0 或者布尔值 True,则代码
if_suite 执行,否则执行下一条语句。
If 语句标准格式:
If expression:
If suite
注释:suite 是 Python 术语,它由一条或多条语句组成。
代码举例:
If x == 12:
print(‘You are true!’)
if 语句还可以与 else 连用:
接上述代码:
else:
print(‘Try again!’)
除此之外,Python 还支持 elif 语句(也称 else-if 语句)
elif 语句格式:
if expression1:
if_suite
elif expression2:
elfe_suite
else expression3:
else_suite
这就是 if 语句了。
评论0