易截截图软件、单文件、免安装、纯绿色、仅160KB

python 笔记 for loop and extend, append

list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html 这几天看一下
python howto
恩。python documentation 确实很好很强大啊!
list.append(x)Add an item to the end of the list; equivalent to a[len(a):] = [x].a[len(a):] 是一个list,slice得到的一个list,相当于把这一段截取出来的list,要是等于一个list b,相当于在a的末尾添加了b,但是b整个是一个元素。>>> c.append([1,2,3])>>> c[1, 2, 3, 4, [1, 2, 3]]list.extend(L)Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.
添加L中的元素,延长a
For loop, for(i=0; i<n; i++) in python is for i in range(0, n)
对于步长为2,则 for i in range(0, n, 2):  range 函数可以改变步长! 不用 i += 2, Mark一下。
for i in range(0,10,2):
    print i

0
2
4
6
8
比如寻找素数的程序。那么,寻找是不是被整除的时候,除了2 之外,可以从3开始,步长为2的去搜索。直到[sqrt(prime_n)](就是int(sqrt(prime_n)), 高斯函数)为止。


相关文档:

Python 线程池的实现

import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *

def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.x ......

Python 中的字符编码

1、str类型可以理解为一个二进制block,或multibyte
2、multibyte_str.decode("<multibyte_encode_method>")  -> unicode
3、unicode_str.encode("<multibyte_encode_method>")  -> multibyte_str(binary block)
4、unicode_str 的操作参数也应为unicode,如:unicode_str.find("样本".deco ......

python的编码问题

  前两天理解了unicode、utf-8、gb2312这些编码之间的关系以后,今天终于弄明白了在python里面的编码问题。我们在写python脚本时如果有中文的字符串,在运行的时候有可能会报错也有可能会出现乱码。一般加上# -*- coding:utf-8 -*-就不会报错了,但是还可能有乱码问题,而且同样的代码在不同的编辑器中得出的结果 ......

Eclipse Python开发环境

1,下载org.python.pydev.feature-1.5.0.1251989166.zip http://sourceforge.net/projects/pydev/files/
2,安装插件到eclipse
3,重启eclipse
注意:使用1.5.6版本pydev插件,创建python工程会报错,使用1.5.0版本无此问题。 ......

基本数据结构的python实现 队列

队列:
与堆栈类似,通过python的列表类型来实现,参考 help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号