#!pyton2
#-*- coding:utf-8 -*- for letter in "Python":
print "Current letter is:",letter fruits=["apple","mango","pear"] for fruit in fruits:
print fruit for index in range(len(fruits)):
print fruits[index] > python2 test.py
Current letter is: P
Current letter is: y
Current letter is: t
Current letter is: h
Current letter is: o
Current letter is: n
apple
mango
pear
apple
mango
pear
numbers=[1,2,3,4,5]
odd=[]
even=[] while len(numbers)>0:
number=numbers.pop()
if number%2==0:
even.append(number)
else:
odd.append(number) print "numbers: ",numbers
print "odd :" ,odd
print "even:",even numbers: []
odd : [5, 3, 1]
even: [4, 2]
#break and continue

i=1
while i<10:
i+=1
if i%2 >0:
continue
print i i=1
while 1:
print i
i+=1
if i>4:
break 2
4
6
8
10
1
2
3
4
#while,else

while count<3:
print count," is less than 3"
count+=1
else:
print count, "is not less than 3" #死循环
flag=1
while flag==1:
print "True!" 0 is less than 3
1 is less than 3
2 is less than 3
3 is not less than 3
True!
True!
True!
True!
True!
True!
True!
#!python2
#-*- coding:utf-8 -*- def test_fun(num,step):
i=0
numbers=[]
while i<num:
print "At the top i is %d " %i
numbers.append(i) i=i+step
print "Numbers now: ",numbers
print "At the bottom i is %d " % i print "The numbers:"
for n in numbers:
print n def test_fun2(num,step):
numbers=[]
for i in range(0,num,step):
print "At the top i is %d" %i
numbers.append(i)
print "Numbers now:", numbers print "The numbers:"
for index in range(len(numbers)):
print numbers[index] def find_prime(start_num,end_num):
for num in range(start_num,end_num):
for i in range(2,num):
if num%i==0:
print "%d = %d * %d" %(num,i,num/i)
break;
else:
print "%d is a prime" % num > python2
Enthought Canopy Python 2.7.11 | 64-bit | (default, Jun 11 2016, 11:33:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ex33_2 import *
>>> find_prime(10,20)
10 = 2 * 5
11 is a prime
12 = 2 * 6
13 is a prime
14 = 2 * 7
15 = 3 * 5
16 = 2 * 8
17 is a prime
18 = 2 * 9
19 is a prime
>>> test_fun(8,4)
At the top i is 0
Numbers now: [0]
At the bottom i is 4
At the top i is 4
Numbers now: [0, 4]
At the bottom i is 8
The numbers:
0
4
>>> test_fun2(8,4)
At the top i is 0
Numbers now: [0]
At the top i is 4
Numbers now: [0, 4]
The numbers:
0
4

Python for loop and while loop的更多相关文章

  1. python list comprehension twos for loop 嵌套for循环

    list comprehension 后面可以有多个for loops,每个for后面可以有if [(x, y, x * y)for x in(0,1,2,3)for y in(0,1,2,3)if ...

  2. C 语言:返回两个数组中第一个相同元素的指针(我用了loop 、goto loop标签)

    // //  main.c //  Pointer_search // //  Created by ma c on 15/8/2. //  要求:通过指针查找,实现比较两个有序数组中的元素,输出两个 ...

  3. PYTHON ASYNCIO: FUTURE, TASK AND THE EVENT LOOP

    from :http://masnun.com/2015/11/20/python-asyncio-future-task-and-the-event-loop.html Event Loop On ...

  4. 简单了解一下事件循环(Event Loop)

    关于我 一个有思想的程序猿,终身学习实践者,目前在一个创业团队任team lead,技术栈涉及Android.Python.Java和Go,这个也是我们团队的主要技术栈. Github:https:/ ...

  5. Why should I avoid blocking the Event Loop and the Worker Pool?

    Don't Block the Event Loop (or the Worker Pool) | Node.js https://nodejs.org/en/docs/guides/dont-blo ...

  6. PostgreSQL-PL/pgSQL-cursor,loop

    将spam_keyword表word字段的字符全部拆分,只是利用过程语言完成循环的操作而已. create or replace function proc1() returns setof text ...

  7. archlinux 加载loop模块,且设定loop设备个数

    如果loop模块没有编译进内核就要先加载loop模块 modprobe loop 然后更改/etc/modprobe.d/modprobe.conf(有些文章写是在/etc/modprobe.conf ...

  8. Run Loop详解

    Run loops是线程的基础架构部分.一个run loop就是一个事件处理循环,用来不停的调配工作以及处理输入事件.使用run loop的目的是使你的线程在有工作的时候工作,没有的时候休眠. Run ...

  9. Objective-C之run loop详解[转]

    做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一门语言还是需要深层次的了解它,这样才能在使用的时候得心应手,出 ...

随机推荐

  1. DOS批处理不支持将UNC 路径作为当前目录的巧妙解决方案

    DOS批处理不支持将UNC 路径作为当前目录的巧妙解决方案在有些时候,需要在批处理中操作UNC目录,但批处理并不能直接对UNC目录进行操作,怎么办? 废话少说,直接上代码,打开网上邻居→整个网络→Mi ...

  2. Qt工程转化为Vs工程

    cmd中输入: qmake -tp vc XXX.pro 一般需要将qmake的路径配置到系统环境变量中去...

  3. DES MAC PIN HEX

    /* void DesEncrypt( UCHAR * auchInput,UCHAR * auchKey,UCHAR * auchOutput=NULL); Function: DesEncrypt ...

  4. 0517Scrum项目4.0

    一.任务看板: 二.任务认领情况: 冯铭杰:界面的设置和部分功能的实现: 梁毅乾:四则运算的功能实现以及代码的维护: 陈施恩:监督小组成员的工作进度,以及代码的编写: 张俊毅:四则运算的算术随机产生: ...

  5. 使用Dottrace跟踪代码执行时间

    当自己程序遇到性能问题,比如IIs请求反应缓慢,客户端程序执行缓慢,怎么分析是哪里出了问题呢?dottrace可以帮助.net程序跟踪出代码里每个方法的执行时间,这样让我们更清晰的看出是哪里执行时间过 ...

  6. NPOI 操作Excel

    关于NPOI NPOI是POI项目的.NET版本,是由@Tony Qu(http://tonyqus.cnblogs.com/)等大侠基于POI开发的,可以从http://npoi.codeplex. ...

  7. 解决 iOS7 通过tag 找不到 UITableViewCell 的子控件

    当iOS7问世,程序的世界就混乱了,以前良好的程序,现在是一塌糊涂,于是只能把问题一个一个攻破. 由于项目当中需要每个cell显示数目不同的图片,于是我在每个cell 赋值之前,通过一下方法把cell ...

  8. python 笔记1:安装python;eclipse中安装配置pydev

    1  下载安装python. 官网:https://www.python.org/downloads/     根据自己的操作系统选择需要的版本下载并安装. 我的电脑操作系统windows xp的,只 ...

  9. Jmeter—6 CSV Data Set Config 通过文件导入数据

    线程组循环次数大于1的时候,请求里每次提交的数据都相同.有的系统限制了不能提交相同数据,我们通过 CSV Data Set Config 加载csv文件数据. 1 创建一个文本文件,输入参数值保存为. ...

  10. SPFA算法学习笔记

    一.理论准备 为了学习网络流,先水一道spfa. SPFA算法是1994年西南交通大学段凡丁提出,只要最短路径存在,SPFA算法必定能求出最小值,SPFA对Bellman-Ford算法优化的关键之处在 ...