2018-11-21 18:23:56

print('pass语句')
for letter in 'Runoob':
if letter=='o':
pass
else:
print(letter) score = int(input('请输入您的分数:'))
if score >=90:
print('A')
if score >=80 and score<90:
print('B')
if score<80:
print('C')
'以上两端代码的效果相等'
if score>=90:
print('A')
elif score>80:
print('B')
else:
print('C') print('计算1到100的和***************************************************************') sum = 0
n = 1
while n <= 100:
sum = sum + n
n = n + 1
print('1到100的和为:',sum) print('while无线循环***************************************************************')
var = 1
while var == 1:
num = int(input('请输入一个整数:'))
print('您输入的数字为:',num) print('while循环使用else语句***************************************************************')
flag = 1
while (flag):print('欢迎访问菜鸟教程!') print('while循环使用else语句***************************************************************') num =0
while num<5:
print('您输入的数小于5',num)
num = num +1
else:
print('您输入的数大于5',num) print('使用for遍历列表中的数据***************************************************************')
sites = ['Google','Baidu','Taobao','Runoob']
for mysite in sites:
print('在呢:',mysite) print('在列表中找到循环对象后停止***************************************************************')
'如果未找到循环对象提示未找到循环对象,如果已找到循环对象提示已找到循环对象' sites = ['Google','Baidu','Runoob','Taobao']
for i in sites:
if i =='Runoob':
print('菜鸟教程:',i)
break
else:
print('不是菜鸟教程哦:',i) print('用for遍历range()生成的一个数列*******************************************************')
for i in range(5):
print(i) print('用for遍历range()生成的一个指定区间的数列**************************************************')
for ii in range(5,10):
print(ii) print('用for遍历range()生成的一个指定区间、步长的数列*********************************************')
for iii in range(5,10,2):
print(iii) print('用for结合range()和len()遍历一个序列的索引***************************************************')
sites2 = ['Google','Baidu','Runoob','Taobao']
i = 0
for i in range(len(sites2)):
print(i,sites2[i])
i = i+1
else:
print('遍历结束') print('使用range()创建一个列表*********************************************************************')
newlist = list(range(5))
print(newlist) print('break语句跳出for循环体***********************************************************************')
'找到一个字符中的某个字母时跳出循环体'
for letter in 'Runoob':
if letter == 'b':
print('找到了;',letter)
break
else:
print('这不是目标:',letter) print('break语句跳出while循环体*********************************************************************')
'从10开始倒序输出,遇到7时跳出循环体'
i =10
while i <=10:
if i ==7:
print('找到了:',i)
break
else:
print('这不是我要的:',i)
i = i-1 print('continue跳过for循环块中的剩余语句************************************************************')
'遇到Runoob中的o时跳过不输出'
for letter in 'Runoob':
if letter == 'o':
continue
print('我是被忽略的:',letter)
else:
print('我不是被忽略的:',letter) print('continue跳过while循环块中的剩余语句********************************************************888')
'*遇到10、9、、、0中的7时跳过不输出'
i = 10
while i > 0:
i = i - 1
if i ==7:
continue
print('我是被忽略的:',i)
else:
print('我不是被忽略的:',i) '''
循环语句可以有 else 子句,它在穷尽列表(以for循环)或条件变为 false (以while循环)导致循环终止时被执行,但循环被break终止时不执行。
如下实例用于查询质数的循环例子:
''' print('pass是空语句,一般用作占位语句************************************************************')
while True:
pass print('end的应用及使用效果对比*******************************************************************')
for i in range(5):
print(i) for i in range(5):
print(i,end='') for i in range(5):
print(i,end=' ') for i in range(5):
print(i,end=',')

17-Python3 循环语句的更多相关文章

  1. Python3 循环语句

    Python3 循环语句 转来的  很适合小白   感谢作者   Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中wh ...

  2. 【python】Python3 循环语句

    [python]几种常见的循环 注意:如果涉及到程序中print语句中含有%d,%s,那么要在脚本最开始写语句:#coding=utf-8,才能够正常输出想要的数字或者字符串. Python3 循环语 ...

  3. Python3循环语句

    Python3 循环语句 Python中的循环语句有for和while. 循环语句控制结构图如下: 一.while循环 ①循环结构 while 判断条件: 执行语句 实例: n = int(input ...

  4. python013 Python3 循环语句

    Python3 循环语句本章节将为大家介绍Python循环语句的使用.Python中的循环语句有 for 和 while.Python循环语句的控制结构图如下所示: while 循环Python中wh ...

  5. python3循环语句while

    Python的循环语句有for和while语句,这里讲while语句. Python中while语句的一般形式: while 条件判断 : 语句 需要注意冒号和缩进.另外,注意Python中没有do. ...

  6. Python3 循环语句(十)

    Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中while语句的一般形式: while 判断条件: 语句 同样需要注意 ...

  7. (四)Python3 循环语句——for

    for循环的一般格式如下: for <variable> in <sequence>: <statements> else: <statements> ...

  8. (三)Python3 循环语句——while

    while语句的一般形式: while 判断条件: 语句 同样需要注意冒号和缩进.另外,在 Python 中没有 do..while 循环. 以下实例使用了 while 来计算 1 到 100 的总和 ...

  9. 17.for循环语句

    for循环: 语法: for(表达式1;表达式2;表达式3){ java语句; } 表达式1是最初始化表达式:最先执行,只执行一次 表达式2必须是boolean 类型的表达式.结果为ture或者fal ...

  10. Python系列:三、流程控制循环语句--技术流ken

    Python条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非 ...

随机推荐

  1. 8月10日CSS总结

    1.三角形光标转换 CSS: .one{ width: 0;­­ height: 0; border-top: 100px solid #000; border-right:100px solid t ...

  2. Linux下coreseek环境安装 、mysql数据源、sphinx扩展安装及php调用

    一.安装m4-1.4.13.autoconf-2.64.automake-1.11.libtool-2.2.6 下载安装m4-1.4.13.autoconf-2.64.automake-1.11.li ...

  3. [No000016B]清华maven库配置settings.xml

    路径:"C:\Users\%USERNAME%\.m2\settings.xml" <settings xmlns="http://maven.apache.org ...

  4. [No0000124]WPF 扩展控件Behavior的几种方式

    一.使用Attached Dependency Property的方式 (1)定义Attached Dependency Property public static class DigitsOnly ...

  5. TensorRT优化过程中的dropout问题

    使用tensorRT之前,你一定要注意你的网络结构是否能够得到trt的支持,无论是CNN还是RNN都会有trt的操作. 例如:tf.nn.dropout(features, keep_prob),tr ...

  6. GlusterFS分布式存储系统中更换故障Brick的操作记录1

    前面已经介绍了GlusterFS分布式存储集群环境部署记录,现在模拟下更换故障Brick的操作: 1)GlusterFS集群系统一共有4个节点,集群信息如下: 分别在各个节点上配置hosts.同步好系 ...

  7. wpf数据绑定:xml数据绑定

    wpf中可以通过XmlDataProvider,来实现xml数据的绑定.它通过XmlDataProvider来绑定外部资源,需要命名一个 x:Key 值,以便数据绑定目标可对其进行引用,Source设 ...

  8. io.UnsupportedOperation: not readable

    两处错误一.你是用open打开一个文件,此时调用的是w写入模式,下面使用read是没有权限的,你得使用w+读写模式二.使用write写入一个字符s,但是此时并没有真正的写入,而是还存在与内存中.此时执 ...

  9. python知识点杂记2

    1. 如果已经有一个list或者tuple,要调用一个可变参数怎么办?2. >>> nums = [1, 2, 3]3. >>> calc(*nums)4. 14* ...

  10. springboot注入properties配置到javabean

    一.再application.properties中添加 二. @Value("${field}")在字段上面加个注解