1 while break continue

 #while语句
'''
while 判断条件:
执行语句……
'''
count = 0
while (count < 9):
print ('The count is:', count)
count = count + 1 print ("Good bye!") # continue 和 break 用法 i = 1
while i < 10:
i += 1
if i%2 > 0: # 非双数时跳过输出
continue
print (i) # 输出双数2、4、6、8、10 i = 1
while 1: # 循环条件为1必定成立
print (i) # 输出1~10
i += 1
if i > 10: # 当i大于10时跳出循环
break #死循环
'''
var = 1
while var == 1 : # 该条件永远为true,循环将无限执行下去
num = raw_input("Enter a number :")
print "You entered: ", num print "Good bye!"
''' #while … else
count = 0
while count < 5:
print (count, " is less than 5")
count = count + 1
else:
print (count, " is not less than 5") #简单语句组
flag = 1
while (flag): print ('Given flag is really true!');flag=0;
print ("Good bye!")

1.1 break continue pass

 #break语句
for letter in 'Python': # First Example
if letter == 'h':
break
print ('Current Letter :', letter) var = 10 # Second Example
while var > 0:
print ('Current variable value :', var)
var = var -1
if var == 5:
break print ("Good bye!") #continue语句
for letter in 'Python': # 第一个实例
if letter == 'h':
continue
print ('当前字母 :', letter) var = 10 # 第二个实例
while var > 0:
var = var -1
if var == 5:
continue
print ('当前变量值 :', var)
print ("Good bye!") #pass语句
# 输出 Python 的每个字母
for letter in 'Python':
if letter == 'h':
pass
print ('这是 pass 块')
print ('当前字母 :', letter) print ("Good bye!")

2 for

 #for语句
'''
for iterating_var in sequence:
statements(s)
'''
for letter in 'Python': # 第一个实例
print ('当前字母 :', letter) fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # 第二个实例
print ('当前水果 :', fruit) print ("Good bye!")

2.1 序列索引迭代

 #序列索引迭代
fruits = ['banana', 'apple', 'mango']
for index in range(len(fruits)):
print ('当前水果 :', fruits[index]) print ("Good bye!") #for...else
for num in range(10,20): # 迭代 10 到 20 之间的数字
for i in range(2,num): # 根据因子迭代
if num%i == 0: # 确定第一个因子
j=num/i # 计算第二个因子
print ('%d 等于 %d * %d' % (num,i,j))
break # 跳出当前循环
else: # 循环的 else 部分
print (num, '是一个质数')

python学习笔记3-循环1的更多相关文章

  1. 【Python学习笔记】循环和迭代

    for和while基本语法 break和continue else的使用 enumerate和zip在循环中的应用 for和while基本语法 Python中的的循环使用for和while语句来实现, ...

  2. python学习笔记:循环语句——while、for

    python中有两种循环,while和for,两种循环的区别是,while循环之前,先判断一次,如果满足条件的话,再循环,for循环的时候必须有一个可迭代的对象,才能循环,比如说得有一个数组.循环里面 ...

  3. python学习笔记--for循环

    推荐一个学习语言的网站:http://www.codecademy.com 有教程,可以边学边写,蛮不错的. for循环: 1.for loops allow us to iterate throug ...

  4. Python 学习笔记9 循环语句 For in

    For in 循环主要适用于遍历一个对象中的所有元素.我们可以使用它遍历列表,元组和字典等等. 其主要的流程如下:(图片来源于: https://www.yiibai.com/python/pytho ...

  5. Python 学习笔记8 循环语句 while

    While循环是哟中利用条件语句,不断的执行某一段代码块,达到批量操作输出等一系列的操作,直到条件不满足或者被强制退出为止. 其工作流程如下: (图片来源菜鸟教程:http://www.runoob. ...

  6. python学习笔记四——循环及冒泡排序

    3.3.3 break 和 continue语句 break:跳出整个循环 continue:跳出当前循环继续后面的循环 例: x=int(input("please input the ' ...

  7. python 学习笔记(循环,print的几种写法,操作符)

    一.循环( for, while) while循环是指在给定的条件成立时(true),执行循环体,否则退出循环.for循环是指重复执行语句. break 在需要时终止for /while循环 cont ...

  8. python学习笔记1 循环、列表、元祖、数据类型

    if语法:基于python3语法 if a<b: 冒号结尾 print("yes") 注意语句的缩进需要一致,不然会报语法错误. elif a==b: print(" ...

  9. python学习笔记 - for循环: 遍历字典, 分别打印key, value, key:value

    #遍历字典, 分别打印key, value, key:value emp = {'name':'Tom', 'age':20, 'salary' : 8800.00} for k in emp.key ...

  10. 【python学习笔记】5.条件、循环和其他语句

    [python学习笔记]5.条件.循环和其他语句 print: 用来打印表达式,不管是字符串还是其他类型,都输出以字符串输出:可以通过逗号分隔输出多个表达式 import: 导入模块     impo ...

随机推荐

  1. 大话大前端时代(一) —— Vue 与 iOS 的组件化

    序 今年大前端的概念一而再再而三的被提及,那么大前端时代究竟是什么呢?大前端这个词最早是因为在阿里内部有很多前端开发人员既写前端又写 Java 的 Velocity 模板而得来,不过现在大前端的范围已 ...

  2. python远程访问hive

    #!/usr/bin/pythonimport syssys.path.append('/home/zhoujie/Downloads/hive-0.7.0-cdh3u0/lib/py')from h ...

  3. 【paddle学习】图像分类

    https://zhuanlan.zhihu.com/p/28871960 深度学习模型中的卷积神经网络(Convolution Neural Network, CNN)近年来在图像领域取得了惊人的成 ...

  4. 【LeetCode】Generate Parentheses 解题报告

    [题目] Given n pairs of parentheses, write a function to generate all combinations of well-formed pare ...

  5. 系统重装 WIN7如何创建和使用VHD文件

    1 在磁盘管理中,点击操作-创建VHD,然后可以创建一个空的VHD文件   2 右击这个磁盘,点击初始化磁盘,然后可以新建简单卷   3 右击这个磁盘,设置为脱机或者联机就可以在计算机中显示和隐藏这个 ...

  6. FLEX接收外部参数 .

    FLEX参数传递与FLASH有点不同 login..swf?name=aa&password=bb Flex上是这样接收参数的 myname=mx.core.Application.appli ...

  7. cs6 mac 破解方法

    Photoshop CS6 重点功能: 1.Photoshop CS6 包含Photoshop CS6和Photoshop CS6 Extended中所有功能,快去试一试3D图像编辑和Photosho ...

  8. linux 输入子系统(4) intput_dev 接口描述

    Name struct input_dev - represents an input device Synopsis struct input_dev { const char * name; // ...

  9. WPF数据验证(5)―― 错误模板

    <Style TargetType="{x:Type TextBox}">            <Setter Property="Validatio ...

  10. Spring源码深度解析——笔记

    1.spring容器的基本用法 xml配置 <bean id="myTestBean" class="bean.MyTestBean"/> 调用 B ...