Python---循环语句

时间:2014-08-29 03:05:27   收藏:0   阅读:230
1.for循环
#!/usr/bin/evn python
#Filename: for.py

for i in range(1, 5):
    print i
else:
    print ‘The for loop is over‘

2.break语句
#!/usr/bin/evn python
#filename: break.py

while True:
    s = raw_input(‘Enter something : ‘)
    if s == ‘quit‘:
        break
    print ‘Length of the string is‘, len(s)
print ‘Done‘

3.continue语句
#!/usr/bin/evn python
#filename: continue.py

while True:
    s = raw_input(‘Enter something:‘)
    if s == ‘quit‘:
        break
    if len(s) < 3:
        continue
    print ‘Input is of sufficient length‘


本文出自 “笔记” 博客,请务必保留此出处http://sunflower2.blog.51cto.com/8837503/1546260

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!