Python入门(五)流程控制、循环简介

for循环:在python for 循环遍历序列,如一个列表或者字符
#coding:utf8
infoList = ['nan','shuai','qian']
for x in infoList:
	if x == 'shuai':
		print 'with first'
	elif x == 'qian':
		print 'with second'
	elif x == 'nan':
		print 'with ugly'
	else:
		print 'go out'



打印九九乘法表
#coding:utf8

for x in range(1,10):
	for y in xrange(1,10):
		print x,y, x*y



循环控制:
break, 结束循环
continue, 跳过本次循环后继续
pass. 占位,代码桩

for i in range(10):
	if i == 2:continue
	if i == 10: break
	if i == 4: pass
	print i  

你可能感兴趣的:(python)