generator1.py 422 B

12345678910111213141516171819202122232425
  1. def f(x):
  2. print('a')
  3. y = x
  4. print('b')
  5. while y > 0:
  6. print('c')
  7. y -= 1
  8. print('d')
  9. yield y
  10. print('e')
  11. print('f')
  12. return None
  13. for val in f(3):
  14. print(val)
  15. #gen = f(3)
  16. #print(gen)
  17. #print(gen.__next__())
  18. #print(gen.__next__())
  19. #print(gen.__next__())
  20. #print(gen.__next__())
  21. # test printing, but only the first chars that match CPython
  22. print(repr(f(0))[0:17])