python控制语句:
if判断语句 if 判断语句: 执行.... elif 判断语句: 执行.... else: 执行....
#!/usr/bin/python # -*- coding: UTF-8 -*- # 例2:elif用法 num = 5 if num == 3: # 判断num的值 print 'boss' elif num == 2: print 'user' elif num == 1: print 'worker' elif num < 0: # 值小于零时输出 print 'error' else: print 'roadman' # 条件均不成立时输出
简单的语句组: var = 100 if var == 100: print "var is", var
while循环语句
while 判断条件:
执行....
i = 1 while i < 10: i += 1 if i%2 > 0: continue print i
for循环语句
for iterating_var in sequence:
statements(s)
break,continue语句
pass语句:一般用来占位,不做任何事情