首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 摸索(二) 让小弟我爱上python的一句1000阶乘代码

2013-09-26 
python 摸索(二) 让我爱上python的一句1000阶乘代码expression which is evaluated when the function is

python 摸索(二) 让我爱上python的一句1000阶乘代码

expression which is evaluated when the function is called. The syntax to create a lambda function islambda[arguments]:expression


匿名函数如lambda x,y:x*y 中的x,y表示参数,x*y表示函数内部的表达式

 

【3】xrange([start],stop[,step])

This function is very similar to range(), but returns an “xrange object” instead of a list. This is an opaque sequence type which yields the same values as the corresponding list, without actually storing them all simultaneously. 

这个xrange()和range()很相似,不过range()返回的是list数组,xrange()返回的是type,类似于迭代器

xrange()不会一下子把所有的内容放到内存中,用到再申请。

如:

>>> xrange(1,4)
xrange(1, 4)
>>> range(1,4)
[1, 2, 3]


在在大数据处理和循环中break的时候,xrange()的效率好的不是一星半点。以后再用range()我就剁手。

热点排行