python循环while和for,pythonwhilefor,1.while循环基
python循环while和for,pythonwhilefor,1.while循环基
1.while循环基本语法
while 条件判断:
执行语句
n=0count=0while n<=10: if n%2==0: print(n,end=‘ ‘) count=count+n n=n+1print(‘‘)print(‘0到10之间的偶数的和为:‘,count)
执行结果为
[[email protected] test]# python while.py 0 2 4 6 8 10 0到10之间的偶数的和为: 30
2.for循环基本语法
for in循环:
执行语句
test=‘今天天气好晴朗‘for v in test: print(v)print(‘---end---‘)
执行结果为
[[email protected] test]# python for.py 今天天气好晴朗---end---
3.print语句连续输出多个结果,不同结果之间用逗号隔开
4.print输出不换行,print(‘hello‘, end=‘‘),
5.continue,在循环中如果遇到continue,则终止当前循环,后面的语句都不执行,直接进入下次循环
6.break,在循环中中如果遇到break,则整个循环语句终止
python循环while和for
相关内容
- Python学习基础:If 语句与 While 语句,pythonwhile,If 语句用
- python可变和不可变类型,python可变类型,时长总结一下
- Python之Web2py框架使用,,本文主要是对Web2
- threading模块,python下的多线程,threadingpython,一、GIL全局
- python 基础课程,,先来个练习统计统计一
- python异常中的else作用,,一、概念异常:常见的
- 如何用Python制作3D动态航线图,,GeoLines(地
- python fileinput 模块,, 典型用法: im
- python——元组(tuple)基本操作,,元组被称为只读列表
- python蹇€熻鍙栧ぇ鏁版嵁,,鏍囩锛?a hre
评论关闭