#条件判断和循环
1、Python之if语句
score = 75
if score >= 60: #注意if语句以“:”截止
print 'passed' #具有相同缩进的代码被视为同一代码块。
print 'good'
print 'end'
注意缩进为4个空格,不要用tab键,也不要空格和tab键同时使用,以免出错。
2、if...else...
score = 55
if score >= 60:
print 'passed'
else: #注意else后面要加“:”
print 'not passed'
3、if...elif...else
4、for循环
L = ['a', 'b', 'c']
for name in L
print name
name变量是在for循环语句里定义的。
for循环语句的执行过程:先依次取L中的值,然后再赋值给变量name,然后再打印出name的值
5、while循环
N = 10
x = 0
while x < N: #记得在while条件后加“:”
print x
x = x + 1