Chinaunix首页 | 论坛 | 博客
  • 博客访问: 277114
  • 博文数量: 113
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1044
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-15 16:09
文章分类

全部博文(113)

文章存档

2016年(5)

2015年(108)

我的朋友

分类: Python/Ruby

2015-09-03 23:58:03

#1.py
break 终止循环
exit() 整个代码结束

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. s='hello'
  3. l=[1,2,3,'a','b']
  4. t=(7,8,9,'x','y')
  5. d={1:111,2:222,3:333,5:555}
  6. for x in range(1,11):
  7.      print x
  8.       if x==2 :
  9.             print  "hello 222"
  10.             continue
  11.       if x==5 :
  12.             exit()
  13.      if (x==6):
  14.        break     
  15.     else :  print  "#"*5    //输出5个#
  16. else : print "ending"
  17. for x in range(1,11):
  18.      print "-------->",x
#2.py

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. #time yanshi
  3. import time
  4. s='hello'
  5. l=[1,2,3,'a','b']
  6. t=(7,8,9,'x','y')
  7. d={1:111,2:222,3:333,5:555}
  8. for x in range(1,11):
  9.      print x
  10.      time.sleep(1)
#3.py       "q"退出循环

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. while 1:
  3.     print "hello"
  4.     x=raw_input("please input something ,q for quit:")
  5.     if x=="q" :
  6.         break
#4.py

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. x=" "    // 这里x初始化为空
  3. while x !="q" :
  4.     print "hello"
  5.     x=raw_input("please input something ,q for quit:")
#5.py

点击(此处)折叠或打开

  1. #!/usr/bin/python
  2. x=" "
  3. while x !="q" :
  4.     print "hello"
  5.     x=raw_input("please input something ,q for quit:")
  6.      if x=="c" :
  7.          continue
  8.      print "one more time~~~~~"
  9. else :
  10.     print "ending.........."

              python 1.py
hello
please input something ,q for quit:aaa
one more time~~~~~
hello
please input something ,q for quit:c
hello
please input something ,q for quit:aaa
one more time~~~~~
hello
please input something ,q for quit:q
one more time~~~~~
ending..........

      
                






阅读(1101) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~