python 基础 2.4 while 循环
#/usr/bin/python
#coding=utf-8
#@Time :2017/10/18 15:31
#@Auther :liuzhenchuan
#@File :while 循环.py 示例1:
n = 0
while True:
print 'hello world'
if n == 10:
break
n +=1
打印如下:
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
示例2:
n = 0
while True:
if n==10:
break
print n ,'hello'
n +=1
打印如下:
0 hello
1 hello
2 hello
3 hello
4 hello
5 hello
6 hello
7 hello
8 hello
9 hello
示例3:
#条件为假的时候,也是退出循环.输入空字符的时候也退出循环
rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if rinput == '':
break
示例4:
#应用逻辑非判断,退出while循环。while条件为假时,退出while循环
rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if not rinput :
break
示例5:
# while...else...:正常结束while循环时会打印else后面的语句.与for...else...循环体一样
rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if not rinput :
break
else:
print 'hello world'
示例6:
#while 循环嵌套if循环体,支持contine
rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if not rinput :
break
elif rinput == 'quite':
continue
print 'continue'
else:
print 'hello world'
python 基础 2.4 while 循环的更多相关文章
- 『Python基础-7』for循环 & while循环
『Python基础-7』for循环 & while循环 目录: 循环语句 for循环 while循环 循环的控制语句: break,continue,pass for...else 和 whi ...
- Python基础(2)——循环和分支[xiaoshun]
一.瞎扯 世界上一切的系统都可以被'分支'表示.循环也是分支,只不过又重复之前的'分支'选择罢了.程序如人生,每一次的'分支',每一次的选择,都会有不同的结果: 有的选择止步不前,无限循环: 有的选择 ...
- Python基础数据类型与for循环
数据类型:int,bool,str,list, tuple元组,dict字典. 1.数字:12,3,4 在使用print打印数字时,在终端界面中无法判断出打印的是什么类型,当我们需要知道一个值是什么类 ...
- Python基础之条件和循环
阅读目录 一.if语句 1.1功能 1.2语法 1.2.1:单分支,单重条件判断 1.2.2:单分支,多重条件判断 1.2.3:if + else 1.2.4:多分支if + elif +else 1 ...
- Python基础7- 流程控制之循环
循环: 把一段代码重复性的执行N次,直到满足某个条件为止. 为了在合适的时候,停止重复执行,需要让程序出现满足停止循环的条件.Python中有三种循环(实质只有两种): while循环 for循环 嵌 ...
- Python基础(条件判断和循环) if elif else for while break continue;
条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= ...
- Python之路,Day2 - Python基础,列表,循环
1.列表练习name0 = 'wuchao'name1 = 'jinxin'name2 = 'xiaohu'name3 = 'sanpang'name4 = 'ligang' names = &quo ...
- Python基础 条件判断和循环
pyhton if 语句 if 语句后接表达式,然后用: 表示代码块. age = 20 if age >= 18: print 'your age is', age print 'adult' ...
- Python基础、判断、循环、列表、字典,day1
一.Python 简介 1.介绍 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标 ...
- 【Python基础】之for循环、数组字典
一. for循环实例 1.循环字符串 Python Shell: for i in "hello": print(i) h e l l o 2.循环数组Python Shell: ...
随机推荐
- hdu 4524(模拟)
郑厂长系列故事——逃离迷宫 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- Python Challenge 第十关
第十关是一张牛的图片和一行字:len(a[30])=?.图片中的牛是一个链接,点开后进入一个新页面,只有一行字: a = [1, 11, 21, 1211, 111221, 看来要知道第31个数多长, ...
- TreeMap和TreeSet的区别与联系
TreeMap 和 TreeSet 是 Java Collection Framework 的两个重要成员,其中 TreeMap 是 Map 接口的常用实现类,而 TreeSet 是 Set 接口的常 ...
- JAVA基础之Set接口
个人理解: Set接口是Collection接口的子类,其继承了所有方法,HashSet集合则实现了Set接口,其内部存储数据时依靠哈希表,一个类似数组和链表的结合体.设置空集合时,存在默认的容量和加 ...
- 调试SQLSERVER (一)生成dump文件的方法
http://www.cnblogs.com/lyhabc/p/4184149.html http://www.cnblogs.com/lyhabc/p/4185399.html
- Linux命令大总结
from http://elain.blog.51cto.com/3339379/623310 Linux命令大总结------------------------------------------ ...
- app中获取应用名称,版本等信息的方法
在app中,我们有时候需要显示一些信息,例如名称,版本等等...如果用写死的方式可能不太好,我们可以动态的读取.应用的信息主要是在info.plist这个文件中,实际就是一个xml文件,以源文件的方式 ...
- 由ASIHttpRequest里的block引发的思考
项目发http请求,现在一般的都是用的第三方开源库,当然发异步请求时我们也会写几个回调函数来进行请求返回时的处理.不过前段时间看一个朋友写的代码,里面很用block简单的实现了回调相关的部分.比如: ...
- hduoj1285确定比赛名次
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 手机APP自动化持续集成方案
自动化测试流程 自动化测试框架