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

【python笔记 二 】python语句

时间:2016-02-17 19:20:48      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:while   for   if   break   continue   python语句   

1.for语句:

脚本实例:

#!/usr/bin/python

for i in range(1,15):

    print i

else:

    print ‘The loop is done !‘


2.while/if语句:

脚本实例:

#!/usr/bin/env python

#FileName:while1.py

running = True

a = 20

b = int(raw_input(‘Enter A number b: ‘))

while running:

    if a == b:

        print ‘ good,Your number is Ture ! !‘

        running = False    #状态为False则终止循环

    else:

        print ‘Bad,Pleas Try Again!‘

print ‘Done‘

3.break语句:

脚本实例:

#!/usr/bin/env python

#FileName:while1.py

running = True

a = 20

b = int(raw_input(‘Enter A number b: ‘))

while running:

    if a == b:

        print ‘ good,Your number is Ture ! !‘

        break    #终止循环

    else:

        print ‘Bad,Pleas Try Again!‘

print ‘Done‘

4.continue语句:

脚本实例:

#!/usr/bin/python

#FileName:continue.py

while True:

        A = int(raw_input(‘Enter A Number:‘))

        if A == 23:

                print "The number is %s !" % A

                break

        if A != 23:

                print "please continue enter number."

                continue    #符合该条件则继续循环

print "Done"


【python笔记 二 】python语句

标签:while   for   if   break   continue   python语句   

原文地址:http://liupengfang1015.blog.51cto.com/6627801/1742770

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