Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Python
                yanxu@staff.sina.com.cn




2009   11   4
yield




2009   11   4
def f1(t):
                   newt = []
                   for i in t:
                       newt.append(i+1)
           ...
[i+1 for i in arr]

                (i+1 for i in arr)




2009   11   4
__call__




2009   11   4
class M(object):
                    def __init__(self,f):
                       self.f = f
                    def __cal...
>>>t2 = M(2)
                >>>t2(5)
                10
                >>>t3 = M(3)
                >>>t3(10)
          ...
2009   11   4
__len__




2009   11   4
class A(object):
                    def __len__(self):
                       return 10




2009   11   4
>>>a = A()
                >>>len(a)
                10




2009   11   4
from multiprocessing import Process,Pool,cpu_count




2009   11   4
Meta Class




2009   11   4
New Style vs Old Style




2009   11   4
DClass = type(‘DClass’,(object,),{‘spam’:‘eggs’})




2009   11   4
Upcoming SlideShare
Loading in …5
×

Python交流

1,080 views

Published on

  • Be the first to comment

Python交流

  1. 1. Python yanxu@staff.sina.com.cn 2009 11 4
  2. 2. yield 2009 11 4
  3. 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. 4. [i+1 for i in arr] (i+1 for i in arr) 2009 11 4
  5. 5. __call__ 2009 11 4
  6. 6. class M(object): def __init__(self,f): self.f = f def __call__(self,v): return v*self.f 2009 11 4
  7. 7. >>>t2 = M(2) >>>t2(5) 10 >>>t3 = M(3) >>>t3(10) 30 >>>callable(t2) True 2009 11 4
  8. 8. 2009 11 4
  9. 9. __len__ 2009 11 4
  10. 10. class A(object): def __len__(self): return 10 2009 11 4
  11. 11. >>>a = A() >>>len(a) 10 2009 11 4
  12. 12. from multiprocessing import Process,Pool,cpu_count 2009 11 4
  13. 13. Meta Class 2009 11 4
  14. 14. New Style vs Old Style 2009 11 4
  15. 15. DClass = type(‘DClass’,(object,),{‘spam’:‘eggs’}) 2009 11 4

×