fork download
  1. import itertools
  2.  
  3. def xfibo():
  4. """
  5. a generator for Fibonacci numbers, goes
  6. to next number in series on each call
  7. """
  8. current, previous = 0, 1
  9. while True:
  10. yield current
  11. # use a tuple swap
  12. current, previous = previous, current + previous
  13.  
  14. # to get selected results of a generator function ...
  15. print("show Fibonacci series 7 through 10:")
  16. for k in itertools.islice(xfibo(), 7, 11):
  17. print(k)
Success #stdin #stdout 0.08s 10864KB
stdin
Standard input is empty
stdout
show Fibonacci series 7 through 10:
13
21
34
55