码迷,mamicode.com
首页 > 编程语言 > 详细

【python之路4】循环语句

时间:2017-01-06 01:21:04      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:port   log   循环语句   import   div   class   输出   utf-8   10个   

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】循环语句

标签:port   log   循环语句   import   div   class   输出   utf-8   10个   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!