分支语句
#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:跳出本次循环,继续执行下一次循环