Day02,Python条件判断及循环

一、条件判断

1、if…else…

if <条件判断1>:

     <执行1>

elif <条件判断2>:

     <执行2>

elif <条件判断3>:

     <执行3>

else:

     <执行4>

image

2、三元运算

result = value1 if … else value2      如果条件为真,result值为value1,反之为value2

image

二、循环

1、for…in…

打印列表

image

计算1-100整数之和

image

2、while…else…

计算1-100整数之和

image

3、break

在循环中,break语句可以提前退出循环

image

4、continue

在循环中,也可以通过continue语句,跳过当前的这次循环,直接开始下一次循环。

image

猜你喜欢

转载自blog.51cto.com/zouqq/2325335