Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. def yield_demo(n):
  2. for j in range(n):
  3. yield triple(j)
  4. print("j is:", j)
  5. print("end of yield_demo")
  6.  
  7.  
  8. def triple(m):
  9. print("inside triple call", m)
  10. return m*3
  11.  
  12.  
  13. for i in yield_demo(5):
  14. print("i is:", i)
  15.  
  16. ## output looks like the following
  17. # inside triple call 0
  18. # i is: 0
  19. # j is: 0
  20. # inside triple call 1
  21. # i is: 3
  22. # j is: 1
  23. # inside triple call 2
  24. # i is: 6
  25. # j is: 2
  26. # inside triple call 3
  27. # i is: 9
  28. # j is: 3
  29. # inside triple call 4
  30. # i is: 12
  31. # j is: 4
  32. # end of yield_demo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement