首页 > 编程语言 > 详细

【python之路4】循环语句

时间:2017-01-06 01:19:56      阅读:199      评论:0      收藏:0      [点我收藏+]

1、while 循环语句

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import time
bol = True
while bol:
    print ‘1‘
    time.sleep(1)
    bol = False

print ‘hello,world!‘

2、无限的输出数字

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import time
n = 0
while True:
    n = n + 1
    time.sleep(1)
    print n

3、打印输出10个数字

#!/usr/bin/env python
# -*- coding:utf-8 -*-
bol = True
n = 0
while bol:
	n = n + 1
	if n == 10:
		bol = False
	print n
print "end"

 4、break退出本循环语句继续向下运行

#!/usr/bin/env python
# -*- coding:utf-8 -*-
n = 0
while True:
	n = n + 1
	print n
	if n == 10:
		break

print "end"

 

【python之路4】循环语句

原文:http://www.cnblogs.com/sunshuhai/p/6254626.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!