码迷,mamicode.com
首页 > 编程语言 > 详细

python 分支语句 循环语句

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

标签:style   for循环   div   banner   str   语句   current   family   strong   

分支语句

#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 分支语句 循环语句

标签:style   for循环   div   banner   str   语句   current   family   strong   

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

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!