
if判断:weather = " body " weather = " body "
if weather = = " rain ":if weather = = " rain ":
print(' studing in home ')print(' studing in home ')
if weather = = ' override ':elif weather = = ' override ':
print(' go fishing ')print(' go fishing ')
if weather = ' override ')如果后跟表达式,请注意冒号并锁定Else不能单独使用,后面直接跟冒号,没有表达式Elif只能跟随,不能单独出现。
三元运算:a = 6
如果a > 5:
打印(图片)
else (false) ->打印(图片如果a > 5 else false)
后者也是一种判断,但它要简洁得多,但只有简单的判断才能使用,过于复杂的判断会给代码的可读性留下深刻印象
的常见判断是:>(大于)、
=(大于或等于)、
3和一个< p>while循环:while与if类似。如果判断为真,缩进的代码将运行,如果判断为假,循环将停止当使用while循环时,应该注意循环必须停止关注判断公式是否为假。while循环后面还可以跟一个else循环。当循环正常结束时,else中的代码将被执行。虽然也可以直接跟真,但是里面必须用中断来终止循环,用中断来终止循环,不会执行其他的内容