首页 > 编程语言 > 详细

python 分支语句 循环语句

时间:2017-04-07 19:48:41      阅读:207      评论:0      收藏:0      [点我收藏+]

分支语句

#if-else
    if a > b:
        print(‘aaa‘)
    else:
        print(‘bbb‘)

#if-elif-else
    if a > b:
        print(‘a>b‘)
    elif a == b:
        print(‘a==b‘)
    else:
        print(‘a<b‘)

循环语句

while 判断条件:
    执行语句
for temp in sequence:
    执行语句
#-*- coding:utf-8 -*-
for letter in ‘python‘:
  
print(‘current letter is %s‘%letter)

 

#-*- coding:utf-8 -*-
fruits = [‘banner‘,‘apple‘,‘orange‘]
for fruit in fruits:
     print(‘current fruit is %s‘%fruit)                                        

 

 

 Python中for else 语句 只要for循环语句不是通过break结束循环,那么无论for循环有没有执行,都会执行else里的语句. while ...else也是一样

 

break:跳出整个循环

continue:跳出本次循环,继续执行下一次循环

 

python 分支语句 循环语句

原文:http://www.cnblogs.com/wgDream/p/6679635.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!