Advertisement
wagner-cipriano

yield generator use example,

Oct 12th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. #yield example
  2. #It helps the function to return a generator object
  3.  
  4. from __future__ import print_function      #Compatibilidade func print python 2/3
  5. import math
  6.  
  7. def Fatorial(Qtde):
  8.     ListIn = range(Qtde)
  9.     for i in ListIn:
  10.         yield math.factorial(i)
  11.  
  12. Qtde = 10
  13. Resp = Fatorial(Qtde)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement