Python03-循环语句&条件语句

  • for循环
  • while循环
  • if语句
  • else语句
  • elif语句

======================================

循环语句

  • for循环——用来遍历任何序列的项目
subject=['math','chinese','art','music']
for i in subject:
    print('我目前正在学习:{}'.format(i))
  • while循环——用来循环执行某程序,即当条件满足时,一直执行某程序,直到不满足时终止。
week=0
while week>7print('当前正是第{}周'.format(week))
    week+=1
print('我在这里已经待了{}周了,可以走了'.format(week))

======================================

条件语句

  • if语句——判断某个条件是否满足
is_study=1
if is_study ==1:
    print('可以找到好工作')
  • else语句——对if语句的补充
is_study=1
if is_study ==1:
    print('可以找到好工作')
else:
    print('再努力一下好了')
  • elif语句——多条语句判断
if score < 60:    print('小于60分')
elif score < 70:
    print('60分到70分')
elif score < 80:
    print('70分到80分')
else:
    print('80-100分')
发布了56 篇原创文章 · 获赞 0 · 访问量 778

猜你喜欢

转载自blog.csdn.net/xiuxiuxiu666/article/details/104315272