码迷,mamicode.com
首页 > 编程语言 > 详细

python 进阶

时间:2016-09-17 21:51:51      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

def generator_function():
	for i in range(10):
		yield i

if __name__ == ‘__main__‘:
	for item in generator_function():
		print item
	gen = generator_function()
	print next(gen)
	print next(gen)
	print next(gen)
	print next(gen)
	l = iter(range(5))
	print next(l)
	my_name = ‘Zsl‘
	my_iter = iter(my_name)
	print type(my_iter)
	print type(next(my_iter))

  生成器可以提升性能

#coding:utf8
‘‘‘@map,的用法理解‘‘‘

items = range(5)
squared = []
for i in items:
    squared.append(i**3)
print squared

#对比-------------

squared2 = map(lambda x: x**3,items)
print squared2

def multiply(x):
    return x*x

def add(x):
    return x+x


funcs = [multiply,add]
for i in items:
    value = map(lambda x: x(i),funcs)#x代表funcs中的对象(它的对象是两个函数),i是x的参数
    print value

 

python 进阶

标签:

原文地址:http://www.cnblogs.com/zsl-3/p/5879606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!