python while循环控制流语句结构与用法
python while循环语句和for语句都是python的主要循环结构。while语句是python中最通用的迭代结构,也是一个条件循环语句。while与if语句有哪些不同,标准语法结构及循环使用方法是本文主要内容。
python while循环语句和if语句有哪些不同之处
要想知道while与if两种语句有何不同,首先要知道while语句的工作原理。
if语句是条件为真True,就会执行一次相应的代码块;而while中的代码块会一直循环,直到循环条件不能满足不再为真。
python while语句一般标准语法
while循环语句的语法如下所示:
python while 条件:
执行代码块
while循环中的执行代码块会一直循环执行,直到当条件不能被满足为假False时才退出循环,并执行循环体后面的语句。python while循环语句最常被用在计数循环中。
python while循环控制流语句基本操作方法
举一个最简单的,不加任何多重条件的例子,来看看while循环控制流语句基本用法是怎么样的
>>>x = 1
>>>while x<10:
>>> x+=1
>>> print x
2
3
4
5
6
7
8
9
10
变量x的初始值为1,条件是x小于10的情况时,执行代码块x+=1的操作,直到x的值不再小于10。
python while循环语句和for语句一样,也是常搭配break、continue、else一起使用,可以完成更多重条件的要求。
玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/jinjie/while.html
相关文章 Recommend
- • 优集品网络科技有限公司招Python中/高级工程师
- • 爱因互动科技发展有限公司招募Python开发攻城狮
- • mozio招聘Python/Django工程师
- • Kavout金融科技公司招Python研发工程师
- • Python数组逆向输出,编程练习题实例四十
- • Python数组插入排序,编程练习题实例三十九
- • Python矩阵for循环应用,编程练习题实例三十八
- • Python操作Redis数据库方面的问题
- • 请python高手帮我看看这段python代码中函数setter的
- • Python什么方法可以快速简洁的将两个队列变成字
- • python re模块中的 match()和group()疑问
- • macos x中python是默认就有的吗?
PYTHON基础入门必备教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
PYTHON进阶提高必备教程 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • Python IOError错误异常原因
- • Python列表排序 reverse、sort、sorted 操作方法
- • 使用 from import方法导入Python模块
- • Python break语句 跳出循环
- • Python return语句 函数返回值
- • Python import语句导入模块语法
- • python assert 断言详细用法格式
- • Python 字典删除元素clear、pop、popitem
- • Python列表添加 insert() 插入元素方法
- • Python SyntaxError语法错误原因及解决
图文精华 RECOMMEND
-
Python列表排序 reverse、sort、sorte
-
Python break语句 跳出循环
-
Python return语句 函数返回值
-
Python import语句导入模块语法
-
python assert 断言详细用法格式
-
Python列表添加 insert() 插入元素方
热点文章 HOT
- Python语言的一些基本常用语句
- Python 字典items返回列表,iteritems返回迭代
- Python函数的形参和实参详解
- Python is同一性运算符和==相等运算符区别
- Python for循环控制语句一般格式及方法
- Python 序列的概念及基本操作方法
- python assert 断言详细用法格式
- python if控制流语句 语法笔记
- Python 函数的关键字参数和位置参数
- Python条件语句的嵌套使用