Python交流
- 1. Python
yanxu@staff.sina.com.cn
2009 11 4
- 3. def f1(t):
newt = []
for i in t:
newt.append(i+1)
return newt
def f2(t):
for i in t:
yield i+1
2009 11 4
- 4. [i+1 for i in arr]
(i+1 for i in arr)
2009 11 4
- 6. class M(object):
def __init__(self,f):
self.f = f
def __call__(self,v):
return v*self.f
2009 11 4
- 7. >>>t2 = M(2)
>>>t2(5)
10
>>>t3 = M(3)
>>>t3(10)
30
>>>callable(t2)
True
2009 11 4