Python2.x_流程控制

 

一 条件判断

1 if...

2 if...else...

3 if...elif...else...

#coding:utf-8
sex = 'Male'
if sex == 'Male':
    print ''
elif sex == 'Femal':
    print ''
else:
    print '人妖?'

二 循环语句

1 for...in...

sum = 0
for x in range(1,6): 
    sum = sum + x 
print 'sum=%d'%sum # sum=15

2 while...

n, sum = 5, 0
while n > 0:
    sum, n = sum + n, n - 1
print 'sum=%d'%sum # sum=15
posted @ 2015-07-05 15:27  yoleimei  阅读(118)  评论(0编辑  收藏  举报