易截截图软件、单文件、免安装、纯绿色、仅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中reactor,factory,protocol的学习笔记


Python中reactor,factory,protocol的学习笔记
 
 
最为简单的情况下,除了了解清reactor的简单使用,你还要了解Protocol和Factory。它们最终都会由reactor的侦听建立和run来统一调度起来。    
   
     建立服务器的第一个要解决的问题就是服务与外界的交流协 ......

话说Python(三)万恶的编码

万恶的编码
小菜对于老师上一节讲的不是很明白,因为没有一本书是将文件与web一起讲授的,他决定自己探究一下它们之间的不同:
首先,小菜在C盘建了一个文本文档 file.txt,输入四个字:我是小菜。
然后,小菜在shell中练习起来:
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>> ......

python的变参


python的变参
*args和**dargs是Python的两个可
变参数,两者有所不同的是*args是个tuple,**dargs是个dict。
*args
和**dargs并用时,*args必须放在**dargs的前面。
例如:
def func(a,b, *c):
    pass
函数func至少有两个参数变参数放在tuple  c中
def func(*c): 或者 def  func(**d ......

Install Python + Eric IDE


Install Python Eric IDE
1 Download following things
 
1) Python3.1
 
2) PyQt for python 3.1
(http://www.riverbankcomputing.co.uk/software/pyqt/download) I am using
PyQt-Py3.1-gpl-4.7.3-2.exe
 
3) Eric5 IDE
(http://eric-ide.python-projects.org/eric-download.html)
 
2 ......

Python TKinter Gui: Toplevel window

#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号