Skip to content

Instantly share code, notes, and snippets.

@vbmendes
Created March 9, 2012 17:24
Show Gist options
  • Save vbmendes/2007646 to your computer and use it in GitHub Desktop.
Save vbmendes/2007646 to your computer and use it in GitHub Desktop.
Exemplo de uso de yield e __iter__
def fib(quantidade):
a, b = 0, 1
for i in xrange(quantidade):
yield b
a, b = b, a + b
class Fib(object):
def __init__(self, quantidade):
self.quantidade = quantidade
def __iter__(self):
return fib(self.quantidade)
for i in Fib(10):
print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment